React Native项目iOS打包发布流程
2018-02-21 本文已影响0人
eternaldyc
1.RN源文件项目打包生成bundle文件
在package.json文件中,添加iOS打包命令如下:
{
...
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
...
"bundle-ios":"node node_modules/react-native/local-cli/cli.js bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ios/bundle/index.ios.jsbundle --assets-dest ios/bundle"
}
...
}
注意:需要事先在项目的ios文件目录下建立bundle子文件夹,不然打包过程会报错【ENOENT: no such file or directory, open 'ios/bundle/index.ios.jsbundle'】。
2.运行打包命令生成bundle文件
npm run bundle-ios
3.在Xcode编辑器中,导入bundle文件
注意:
1.导入方法:将文件夹拖入项目主目录即可
2.注意导入选项:Create folder references

4.代码中添加对bundle的引用
在AppDelegate.m中修改jsCodeLocation变量的值为:
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"bundle/index.ios" withExtension:@"jsbundle"];
