1.在项目的 ios 目录下 新建 bundle 文件夹
2.在项目目录中运行以下命令
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ./ios/bundle/index.ios.jsbundle --assets-dest ./ios/bundle
- --entry-file ios或者android入口的js名称 index.js
- --platform 平台名称(ios或者android)
- --dev 设置为false的时候将会对JavaScript代码进行优化处理。
- --bundle-output 生成的jsbundle文件的名称 ./ios/bundle/index.ios.jsbundle
- --assets-dest 图片以及其他资源存放的目录 ./ios/bundle
成功之后如下提示, 可以看到 ios/bundle 中已经生成了离线资源
3. Add Files to ""
4.修改 AppDelegate.m 文件 把之前的 jsCodeLocation 注释就行
//开发环境
//jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
//打包环境
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
5.修改release模式
6.开始打包 将模拟器调成 Generic iOS Device 然后 按 commd + b (看是否运行正常) , 可以的话点击 Archive
7. 好了之后可以看到如下界面(Window => Organizer 可以打开此页面)首先 Validate App 验证 然后可以 上传到App store 或者其他