【React Native】iOS离线打包
2016-10-19 15:32
302 查看
我们可以用React Native提供的命令:react-native bundle
Options:
**–entry-file Path to the root JS file, either absolute or relative to JS root [required]
–platform Either “ios” or “android”
–transformer Specify a custom transformer to be used (absolute path) [default: “/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js”]
–dev If false, warnings are disabled and the bundle is minified [default: true]
–prepack If true, the output bundle will use the Prepack format. [default: false]
–bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json
–bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]
–bundle-encoding Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer)..) [default: “utf8”]
–sourcemap-output File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map
–assets-dest Directory name where to store assets referenced in the bundle
–verbose Enables logging [default: false]**
其实用Xcode打开后可以开到main.js文件,不过是红色状态的,因为引用了但是并没有这个文件存在,React Native这样做的目的可能就是提示你还没有生成离线数据的意思吧。
所以我们这里的bundle-output就选择这个main.js,如果你想用别的名字,理论上是可以的,但是会提示找不到这个文件,你需要先生成一个空的文件就可以了。
–assets-dest选择./ios就可以了,因为它会帮你在./ios下生成assets文件夹。
操作1:
准备就绪,开始打包。打包完后你就会看到main.js文件变为已有状态了。
然后打开Appdelegate.m文件,修改:
操作2:
//jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@”index.ios” fallbackResource:nil];
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@”main” withExtension:@”jsbundle”];
操作3:
然后再把assets文件夹添加到工程中,注意的是必须选择Creat folder references否则运行时将会报错,无法找到文件。
![](http://img.blog.csdn.net/20161019152810882)
最后command+R运行,发现:
![](http://img.blog.csdn.net/20161019152856587)
出现这样的原因是因为Build Phases中Copy Bundle Resources没有添加我们刚才生成的main.js。
操作4:
Options:
**–entry-file Path to the root JS file, either absolute or relative to JS root [required]
–platform Either “ios” or “android”
–transformer Specify a custom transformer to be used (absolute path) [default: “/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js”]
–dev If false, warnings are disabled and the bundle is minified [default: true]
–prepack If true, the output bundle will use the Prepack format. [default: false]
–bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json
–bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]
–bundle-encoding Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer)..) [default: “utf8”]
–sourcemap-output File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map
–assets-dest Directory name where to store assets referenced in the bundle
–verbose Enables logging [default: false]**
其实用Xcode打开后可以开到main.js文件,不过是红色状态的,因为引用了但是并没有这个文件存在,React Native这样做的目的可能就是提示你还没有生成离线数据的意思吧。
所以我们这里的bundle-output就选择这个main.js,如果你想用别的名字,理论上是可以的,但是会提示找不到这个文件,你需要先生成一个空的文件就可以了。
–assets-dest选择./ios就可以了,因为它会帮你在./ios下生成assets文件夹。
操作1:
react-native bundle --entry-file index.ios.js --bundle-output ./ios/main.jsbundle --platform ios --assets-dest ./ios --dev false
准备就绪,开始打包。打包完后你就会看到main.js文件变为已有状态了。
然后打开Appdelegate.m文件,修改:
操作2:
//jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@”index.ios” fallbackResource:nil];
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@”main” withExtension:@”jsbundle”];
操作3:
然后再把assets文件夹添加到工程中,注意的是必须选择Creat folder references否则运行时将会报错,无法找到文件。
最后command+R运行,发现:
出现这样的原因是因为Build Phases中Copy Bundle Resources没有添加我们刚才生成的main.js。
操作4:
相关文章推荐
- 【React Native】iOS离线打包
- iOS离线打包
- iOS离线打包
- React Native工程离线运行(ios)
- iOS离线打包项目升级5+SDK
- HBuilder开发ios App离线打包启动画面无效的解决方法
- react native iOS打包
- react native ios打包到真机
- React Native ios打包
- react native之ios打包ipa
- React Native之真机调试与离线包方式——iOS开发
- React Native iOS端打包
- react native ios打包流程(小白文)
- react native ios打包到真机
- iOS离线打包
- react native 离线ios
- react native ios打包到真机
- 记一次iOS自动化打包走过的坑-关于React Native-iOS项目
- HBuilder HTML 5+ SDK IOS离线打包步骤
- Yum离线安装(一) --- RPM 打包技术与典型 SPEC 文件分析