React Native 打離線包注意事項
阿新 • • 發佈:2019-01-27
react-native bundle
Options(可選引數說明):
--entry-file :JS根目錄檔案(Path to the root JS file, either absolute
or relative to JS root [required])
--platform :選擇平臺--(ios or android)
--transformer :編譯器預設編譯器地址(/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js)
--dev:是否是開發環境,預設為true(If
false, warnings are disabled and the bundle is minified [default: true])
--prepack :是否需要預先包裝,預設為false(If true, the output bundle will
use the Prepack format. [default: false])
--bridge-config :預先打包配置的 檔名稱(File name of a a JSON export
of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json)
--bundle-output :輸出的目錄檔案地址(File name where to store the resulting
bundle, ex. /tmp/groups.bundle [required])
--bundle-encoding :編碼格式,預設utf8(Encoding the bundle should
be written in (https://nodejs.org/api/buffer.html#buffer_buffer). [default:
"utf8"])
--sourcemap-output :結果檔案存放地址 (File name where to store the
sourcemap file for resulting bundle, ex. /tmp/groups.map)
--assets-dest:圖片等資原始檔存放地址(Directory name where to store assets
referenced in the bundle)
--verbose :是否開啟日誌列印,預設為false(Enables logging [default: false])
Android示例:react-native
bundle--entry-fileindex.android.js--bundle-output./android/app/src/main/assets/index.android.bundle--platform
android--assets-dest./android/app/src/main/res/
--devfalse
注意事項
1../android/app/src/main/assets/資料夾必須存在,不存在時需要手動建立一個assets
資料夾
2../android/app/ 這個路徑一定要準確,如果對應專案名稱發生改變,那目錄地址也要做響應的改變
3.執行完拷貝bundle命令之後,在/android/app/目錄下執行 gradle assembleRelease 打包命令
IOS示例:react-native bundle --entry-fileindex.ios.js--bundle-output./ios/bundle/index.ios.jsbundle--platform
ios--assets-dest./ios/bundle--dev
false
注意事項
1../ios/bundle 確保bundle 資料夾一定存在,不存在時需要手動建立一個assets
資料夾
2.開啟Xcode,在Xcode中將生成的assets檔案新增到專案中
3.開啟Appdelegate.m檔案修改:
//jsCodeLocation = [[RCTBundleURLProvider
sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; jsCodeLocation
= [[NSBundle mainBundle]URLForResource:@"main"
withExtension:@"jsbundle"];
4.在xcode 中執行,搞定