主要分為以下幾步
- cd 到你的工程目錄下借宵;
- 執(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 : 平臺設(shè)置不多說
--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"];