react-native ios打包

  1. 通过 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"
    }
  1. 打包只需要在根目录下输入npm run bundle-ios

    切记: 一定要先在项目-->ios下新建bundle文件夹,不然会报错

    运行完会发现 在bundle 文件夹下已经有了内容

  2. Xcode中添加资源到项目中,必须使用Create folder references的方式(也就是文件夹的方式)添加bundle文件夹

  3. 然后就可以按照正常步骤打包啦

注意:要切换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