codePush已經被微軟將其移動到了appcenter中心,後續關於codePush的相關問題都移步到appcenter官網中進行查看https://appcenter.ms
本文只記錄通過codePush對React Native項目進行熱更新的操作,關於集成方面直接查看官方文檔即可(官方集成文檔:https://docs.microsoft.com/zh-cn/appcenter/distribution/codepush/rn-updates)
本地準備:
- 命令如果採用appcenter codepush,則需要安裝appcenter插件
- 命令如果採用code-push,則需要安裝code-push
npm install appcenter -g
nom install code-push -g
集成前,需要在appcenter中創建應用,應用一般會掛在organization下面:
- 登錄狀態下https://appcenter.ms/apps中,注意創建Platform選擇React Native,android和ios平臺需要各自創建應用
應用創建成功後,可以通過網頁界面查看到應用的key,也可以通過命令查看
appcenter codepush deployment list --app <organizationName>/<appName>
通過app進行應用集成,app發佈後,遇到需要進行熱更的情況,可以按需要根據一下命令進行熱更新
bundle打包命令(android的類似)
react-native bundle --entry-file index.js --bundle-output ./ios/bundle/main.jsbundle --platform ios --assets-dest ./ios/bundle --dev false
發佈命令:
// 由於ios配置問題,無法在plist文件中直接讀出版本號,因此通過--t參數手動指定app版本號
// 1 appcenter codepush release-react命令,內部會進行bundle的打包,之後進行appcenter校驗和上傳(如果bundle中的內容和上個版本一致則會上傳失敗)
appcenter codepush release-react -a organizationName/appName --t 4.1.1 -d Production -m --description "1.測試"
// 2 手動指定bundle和assets目錄進行上傳發布
appcenter codepush release -a organizationName/appName -c ./ios/bundle --t 4.1.1 -d Production -m --description "1.測試"
在發佈後,也可以根據需要在appcenter頁面中對發佈的熱更新進行干預
其他命令自行根據appcenter --help獲取:
deployment View and manage your app deployments
patch Update the metadata for an existing CodePush
release
promote Create a new release for the destination
deployment, which includes the exact code and
metadata from the latest release of the
source deployment
release-cordova Release a Cordova update to an app deployment
release-electron Release an Electron update to a deployment
release-react Release a React Native update to an app
deployment
release Release an update to an app deployment
rollback Rollback a deployment to a previous release