通过
react-native bundle
命令可以打包离线资源。为了日后把打包方便,我们把打包指令填在下package.json
下1
2
3"scripts": {
"bundle-ios": "node node_modules/react-native/local-cli/cli.js bundle --entry-file index.js --platform ios --dev false --bundle-output ./ios/bundle/index.jsbundle --assets-dest ./ios/bundle"
}
打包只需要在根目录下输入
npm run bundle-ios
切记: 一定要先在
项目-->ios下新建bundle
文件夹,不然会报错运行完会发现 在bundle 文件夹下已经有了内容
在
Xcode
中添加资源到项目中,必须使用Create folder references
的方式(也就是文件夹的方式)添加bundle
文件夹然后就可以按照正常步骤打包啦
注意:要切换react native首页加载方式
node node_modules/react-native/local-cli/cli.js bundle –entry-file index.js –platform ios –dev false –bundle-output ./ios/bundle/index.jsbundle –assets-dest ./ios/bundle
node node_modules/react-native/local-cli/cli.js bundle –entry-file index.js –platform ios –dev false –bundle-output ../ios/bundle/index.jsbundle –assets-dest ../ios/bundle