react-native 打離線(xiàn)包之iOS篇

主要分為以下幾步

  1. cd 到你的工程目錄下;
  2. 執(zhí)行命令:
    react-native bundle --entry-file index.iOS.js --bundle-output./index.ios.jsbundle --platform ios --assets-dest ./ios --dev false

facebook 官網(wǎng)給出的解釋如下:
react-native bundle
Options:
--entry-file Path to the root JS file, either absolute or relative to JS root [required]
--platform Either "ios" or "Android"
--transformer Specify a custom transformer to be used (absolute path) [default: "/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js"]
--dev If false, warnings are disabled and the bundle is minified [default: true]
--prepack 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

重點(diǎn)關(guān)注幾個(gè)選項(xiàng):
--entry-file:這個(gè)是你要打包的跟文件,通常是index.ios.js,注意路徑不要錯(cuò)了,
--bundle-output:這個(gè)是你要將打包的文件放到哪里,打包的文件起什么名字如:./index.ios.jsbundle
即放入當(dāng)前目錄,名字為index.ios.jsbundle
--platform : 平臺(tái)設(shè)置不多說(shuō)
--assets-dest:這個(gè)是你的資源打包到什么地方,通常是圖片資源,文件資源什么的:如./ios
即將資源打包到ios目錄下。

3.將打包的jsbundle和資源文件拖入工程,其中資源文件要以引用的方式拖入,jsbundle以拷貝方式拖入工程.
4.修改appDelegate.m如下:

//jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];  
jsCodeLocation = [[NSBundlemainBundle]URLForResource:@"index.ios"withExtension:@"jsbundle"];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容