美文网首页
ReactNative热更新发布应用(方式二CodePush:r

ReactNative热更新发布应用(方式二CodePush:r

作者: MTSu1e丶 | 来源:发表于2018-08-03 21:32 被阅读59次

    前言:这里发布应用是配置热更新成功的前提下~

    注:我们所说的根目录指的是package.json所在的目录~

    先看一下流程图:


    2023270-07b1f364999c5238.png

    流程:

    1. 在根目录里右键-新建文件夹-bundles

    2.使用终端在根目录下执行下面命令,打包生成bundle文件

    react-native bundle --platform ios --entry-file index.ios.js --bundle-output ./bundles/main.jsbundle --assets-dest ./bundles --dev false

    当看到以下就说明成功了:

    Scanning 613 folders for symlinks in ../node_modules (14ms)
    Scanning 613 folders for symlinks in ../node_modules (33ms)
    Loading dependency graph, done.
    bundle: start
    bundle: finish
    bundle: Writing bundle output to: ./bundles/index.ios.bundle
    bundle: Done writing bundle output
    

    文件夹里面会看到:


    1.jpg

    注意:首次执行这个命令的时候需要将main.jsbundle和assets文件夹拖到XCode里面
    assets在拖入的时候要选择:Create folder references,如图:

    2.png

    上面操作之后,jsCodeLocation = [CodePush bundleURL];这个方法就会获取到jsCodeLocation了。

    3.发布更新是在终端执行:
    (1)发布的是Production需要指定--deploymentName

    code-push release AppName ./bundles/ 1.0.0 --deploymentName Production --description "1.第一版发布测试" --mandatory true

    (2)发布的是Staging的可以不指定--deploymentName

    code-push release AppName ./bundles/ 1.0.0 --description "1.第一版发布测试" --mandatory false
    注:这里的1.0.0需要跟app版本对应一致

    发布成功之后会在终端看到,这里使用staging为例:

    Upload progress:[==================================================] 100% 0.0s
    Successfully released an update containing the "./bundles/" directory to the "Staging" deployment of the "AppName" app.
    

    注:这里的AppName指的是你在微软那个网站里面创建的app名称,可以使用以下代码在终端上查看:

    code-push app ls

    效果如下:

    ┌────────────┬─────────────────────┐
    │ Name       │ Deployments         │
    ├────────────┼─────────────────────┤
    │ AppName    │ Production, Staging │
    └────────────┴─────────────────────┘
    
    这里的AppName就是我在微软那个账号里面创建的app
    

    4.如果你想查看你发布的每个版本,使用以下命令查看:

    code-push deployment history AppName Staging

    效果如下: 2.png

    5.当你更改js文件里面的东西并且希望发布你的更新的时候,你需要更改完js之后重新到根目录下,运行第3步里面的code-push release...代码,注意这时候应该更改对应的版本号
    如果不更改版本号会报错:

    [Error]  The uploaded package was not released because it is identical to the contents of the specified deployment's current release.
    

    常用命令

    • 安装: npm install -g code-push-cli
    • 注册账号: code-push register
    • 登陆: code-push login
    • 注销: code-push logout
    • 添加项目: code-push app add [app名称]
    • 删除项目: code-push app remove [app名称]
    • 列出账号下的所有项目: code-push app list
    • 显示登陆的token: code-push access-key ls
    • 删除某个access-key: code-push access-key rm <accessKey>
    • 添加协作人员:code-push collaborator add <appName> next@126.com
    • 部署一个环境: code-push deployment add <appName> <deploymentName>
    • 删除部署: code-push deployment rm <appName>
    • 列出应用的部署: code-push deployment ls <appName>
    • 查询部署环境的key: code-push deployment ls <appName> -k
    • 查看部署的历史版本信息: code-push deployment history <appName> <deploymentNmae>
    • 重命名一个部署: code-push deployment rename <appName> <currentDeploymentName> <newDeploymentName>

    参考文章

    codepush中文版
    react-native-code-push
    react native codepush热更新解决成功更新

    相关文章

      网友评论

          本文标题:ReactNative热更新发布应用(方式二CodePush:r

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