React Native项目iOS打包发布流程

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

《React Native项目iOS打包发布流程》 导入选项不要错

4.代码中添加对bundle的引用

在AppDelegate.m中修改jsCodeLocation变量的值为:

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"bundle/index.ios" withExtension:@"jsbundle"];

《React Native项目iOS打包发布流程》 改变jsCodeLocation引用

参考资料:
React Native ios打包 by 姜家志

    原文作者:eternaldyc
    原文地址: https://www.jianshu.com/p/f757cc1b1cb6
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞