目前针对react native 热更新的方案比较成熟的选择有microsoft公司的code-push 传送门,与react-native 中文网的pushy 传送门
本文选择code-push 用来进行对react-native 实现热更新,code-push 包含client端的配置,默认code-push 使用的服务器地址为微软的服务器,但是在国内的网速不是太好。因此可以使用code-push-server 搭建自己的服务器。本文主要介绍了实现热更新 client 和 server 端的配置。
React Native 热更新 借助 code-push-cli 脚手架完成
参考教程 https://blog.csdn.net/dounine/article/details/78529106
code-push 常用命令可查看 https://www.jianshu.com/p/aa296cc8a2cf
官方code-push 命令操作以及简介可查看 https://github.com/Microsoft/code-push/blob/master/cli/README-cn.md
1.react native 热更新 客户端配置
1.首先全局安装code-push-cli
npm install -g code-push-cli
2.然后注册一个code-push 账号(可使用github账号)
code-push register
3.注册成功后将获取的token在当前命令行输入并回车 (如下)
Enter your token from the browser: b0c9ba1f91dd232xxxxxxxxxxxxxxxxx
#成功提示如下方
Successfully logged-in. Your session file was written to /Users/huanghuanlai/.code-push.config. You can run the code-push logout command at any time to delete this file and terminate your session.
如使用自己搭建的code-push-server 可忽略 2 ,3 步骤 并使用以下命令登录到code-push-server
登录可采用以下命令
code-push login http://***.***.***.***
4.使用code-push 添加一个 app
code-push app add AppName android react-native
添加成功后
code-push app add AppName android react-native
#成功提示如下方
Successfully added the "dounineApp-android" app, along with the following default deployments:
┌────────────┬──────────────────────────────────────────────────────────────────┐
│ Name │ Deployment Key │
├────────────┼──────────────────────────────────────────────────────────────────┤
│ Production │ PZVCGLlVW-0FtdoCF-3ZDWLcX58L6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │
├────────────┼──────────────────────────────────────────────────────────────────┤
│ Staging │ T0NshYi9X8nRkIe_cIRZGbAut90a6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │
5.在自己项目中安装react-native-code-push
npm install react-native-code-