1. 打包之前
打包之前需要在ios目录下创建bundle目录
2. 运行打包命令
进入项目根目录 运行
node node_modules/react-native/local-cli/cli.js bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ./ios/bundle/main.jsbundle --assets-dest ./ios/bundle
或者是将打包命令加入到package.json中
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"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/main.jsbundle --assets-dest ./ios/bundle"
}
这样就可以直接运行命令进行打包了
npm run bundle-ios
3. 在xcode中引入文件夹[项目名以javashop为例]
- 右键项目名,选择Add Files to "javashop"
- 在弹出的文件选择框中点击optios配置
- 这里选择Create folder references
4. 更改jsCodeLocation
- 打开项目根目录下的AppDelegate.m
注释掉
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]
添加
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"bundle/main" withExtension:@"jsbundle"];