React Native ios打包
开发React Native的过程成,js代码和图片资源运行在一个 react-native bundleReact Native的
打包命令如下:
为了方便使用,也可以把打包命令写到npm script中: "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start","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/index.ios.jsbundle --assets-dest ./ios/bundle" }, 然后运行命令直接打包:
打包结果: ... transformed 360/360 (100%) [8:56:31 PM] <END> find dependencies (3427ms) bundle: start bundle: finish bundle: Writing bundle output to: ./ios/bundle/index.ios.jsbundle bundle: Done writing bundle output bundle: Copying 5 asset files bundle: Done copying assets 可以看到jsbundle和资源文件已经打包成功。 添加资源离线包生成完成之后,可以在ios目录下看到一个bundle目录,这个目录就是
jsCodeLocation在ios中 NSURL *jsCodeLocation; jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"RNIos" initialProperties:nil launchOptions:launchOptions]; 在开发的过程中可以在这里配置Debug Server的地址,当发布上线的时候,就需要使用离线的jsbundle文件,因此需要设置jsCodeLocation为本地的离线jsbundle。 jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"bundle/index.ios" withExtension:@"jsbundle"]; 离线包里的.jsbundle文件是经过优化处理的,因此运行效率也会比Debug的时候更高一些。 项目代码地址:https://github.com/jjz/react-native/tree/master/RNIos (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |