[关闭]
@iwanglong 2018-11-05T04:36:10.000000Z 字数 1812 阅读 302

React-native 打包bundle

技术


我们知道,在刚开始学习React-native时,一步一步跟着官方文档创建了iOS demo,调试的过程中需要一直启动服务(npm start)。但是在没有启动服务时咱们点击程序,肯定是不行的,哐当又是满屏红了。一万个小羊复现在眼前。。。怎么办呢?

有没有想过在iOS、Android打包发布时,我们用rn写的这些东西咋集成呢?这时候就用到了bundle(因为以前是搞ios专用,Android目前还没有研究,应该是so?),为啥用bundle呢,bundle就是一个文件夹,按照一定标准组织的目录结构。每个iOS APP至少有一个main bundle,这个main bundle包含了app的二进制代码及任何你用到的资源,如图片,声音,HTML文件等。换句话说,主bundle包含了所有资源,这些资源会被编译成二进制代码提交到App Store上。

我们用下面的命令打包集成:

react-native bundle 命令

  1. react-native bundle --entry-file index.js --bundle-output /Users/wanglong/Documents/moreWorkTest/RN/FirstProject/bundle/iosBundle/index.jsbundle --platform ios --assets-dest /Users/wanglong/Documents/moreWorkTest/RN/FirstProject/bundle/iosBundle/ --dev flase
  1. jsCodeLocation = [[NSBundle mainBundle] URLForResource:@”index.ios withExtension:@”jsbundle”];
  1. Options:
  2. entry-file Path to the root JS file, either absolute or relative to JS root [required]
  3. platform Either iOS or android
  4. transformer Specify a custom transformer to be used (absolute path) [default: “/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js”]
  5. dev If false, warnings are disabled and the bundle is minified [default: true]
  6. prepack If true, the output bundle will use the Prepack format. [default: false]
  7. bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json
  8. bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]
  9. bundle-encoding Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer). [default: “utf8”]
  10. sourcemap-output File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map
  11. assets-dest Directory name where to store assets referenced in the bundle
  12. verbose Enables logging [default: false]

老铁们,这样从新运行app以后,不用起服务这样点一下APP试试效果吧。
ok了吧。不过这样的话不能调试了哦,想要调试的话,记得把bundleURL改回去。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注