RN打离线包

作者: 一往情深_b560 | 来源:发表于2018-04-11 13:52 被阅读248次

1.打开终端 cd至项目根目录下

2.执行命令:

react-native bundle --entry-file index.js --bundle-output ./ios/main.jsbundle --platform ios 

也可将此命令在package.json中设置:

"scripts": {    "iosbundle": "react-native bundle --entry-file index.js --bundle-output ./ios/main.jsbundle --platform ios",} 

终端执行 npm run iosbundle 即可等同于👆

3.打开Xcode-右键Add Files To "项目名".   将生成的main.jsbundle导入至native中。

4.修改AppDelegate.m —> didFinishLaunchingWithOptions: 中代码

模拟器调试用👇

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

真机用👇

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

至此,大功告成!!👍 👍 👍 

原文请参考:https://blog.csdn.net/rainbowfactory/article/details/78990919

😘😘😘如果觉得对您有帮助,麻烦请点个❤️哦

相关文章

网友评论

    本文标题:RN打离线包

    本文链接:https://www.haomeiwen.com/subject/zewahftx.html