fragment中文网_更新 · React Native 中文网
時(shí)刻將 React Native 更新到最新的版本,可以獲得更多 API、視圖、開(kāi)發(fā)者工具以及其他一些好東西(譯注:官方開(kāi)發(fā)任務(wù)繁重,人手緊缺,幾乎不會(huì)對(duì)舊版本提供維護(hù)支持,所以即便更新可能帶來(lái)一些兼容上的變更,但建議開(kāi)發(fā)者還是盡一切可能第一時(shí)間更新)。由于一個(gè)完整的 React Native 項(xiàng)目是由 Android 項(xiàng)目、iOS 項(xiàng)目和 JavaScript 項(xiàng)目組成的,且都打包在一個(gè) npm 包中,所以升級(jí)可能會(huì)有一些麻煩。我們會(huì)盡量簡(jiǎn)化這一流程。你可以在項(xiàng)目目錄下使用npx react-native info命令查看當(dāng)前的版本。There's currently two ways for upgrading your React Native project: by using React Native CLI or manually with Upgrade Helper.
React Native CLI#
The React Native CLI comes with upgrade command that provides a one-step operation to upgrade the source files with a minimum of conflicts, it internally uses rn-diff-purge project to find out which files need to be created, removed or modified.
1. Run the upgrade command#The upgrade command works on top of Git by using git apply with 3-way merge, therefore it's required to use Git in order for this to work, if you don't use Git but still want to use this solution then you can check out how to do it in the Troubleshooting section.
Run the following command to start the process of upgrading to the latest version:
npx react-native upgradeCopy
You may specify a React Native version by passing an argument, e.g. to upgrade to 0.61.0-rc.0 run:
npx react-native upgrade 0.61.0-rc.0Copy
The project is upgraded using git apply with 3-way merge, it may happen that you'll need to resolve a few conflicts after it's finished.
2. Resolve the conflicts#
Conflicted files include delimiters which make very clear where the changes come from. For example:
13B07F951A680F5B00A75B9A/* Release */={
isa=XCBuildConfiguration;
buildSettings={
ASSETCATALOG_COMPILER_APPICON_NAME=AppIcon;
<<<<<<
CODE_SIGN_IDENTITY="iPhone Developer";
FRAMEWORK_SEARCH_PATHS=(
"$(inherited)",
"$(PROJECT_DIR)/HockeySDK.embeddedframework",
"$(PROJECT_DIR)/HockeySDK-iOS/HockeySDK.embeddedframework",
);
=======
CURRENT_PROJECT_VERSION=1;
>>>>>>>theirs
HEADER_SEARCH_PATHS=(
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../node_modules/react-native-code-push/ios/CodePush/**",
);Copy
You can think of "ours" as "your team" and "theirs" as "the React Native development team".
Upgrade Helper#
The Upgrade Helper is a web tool to help you out when upgrading your apps by providing the full set of changes happening between any two versions. It also shows comments on specific files to help understanding why that change is needed.
1. Select the versions#
You first need to select from and to which version you wish to upgrade, by default the latest major versions are selected. After selecting you can click the button "Show me how to upgrade".
💡 Major updates will show an "useful content" section on the top with links to help you out when upgrading.
2. Upgrade dependencies#
The first file that is shown is the package.json, it's good to update the dependencies that are showing in there. For example, if react-native and react appears as changes then you can install it in your project by running yarn add:
# {{VERSION}} and {{REACT_VERSION}} are the release versions showing in the diff
yarn add react-native@{{VERSION}}
yarn add react@{{REACT_VERSION}}Copy
3. Upgrade your project files#
The new release may contain updates to other files that are generated when you run npx react-native init, those files are listed after the package.json in the Upgrade Helper page. If there aren't other changes then you can just rebuild the project and continue developing.
In case there are changes then you can either update them manually by copying and pasting from the changes in the page or you can do it with the React Native CLI upgrade command by running:
npx react-native upgradeCopy
This will check your files against the latest template and perform the following:If there is a new file in the template, it is simply created.
If a file in the template is identical to your file, it is skipped.
If a file is different in your project than the template, you will be prompted; you have options to keep your file or overwrite it with the template version.Some upgrades won't be done automatically with the React Native CLI and require manual work, e.g. 0.28 to 0.29, or 0.56 to 0.57. Make sure to check the release notes when upgrading so that you can identify any manual changes your particular project may require.
Troubleshooting#
I want to upgrade with React Native CLI but I don't use Git#
While your project does not have to be handled by the Git versioning system -- you can use Mercurial, SVN, or nothing -- you will still need to install Git on your system in order to use npx react-native upgrade. Git will also need to be available in the PATH. If your project doesn't use Git, initialize it and commit:
git init # Initialize a Git repository
git add . # Stage all the current files
git commit -m "Upgrade react-native" # Save the current files in a commitCopy
After you finish upgrading you may remove the .git directory.
I have done all the changes but my app is still using an old version#
These sort of errors are usually related to caching, it's recommended to install react-native-clean-project to clear all your project's cache and then you can run it again.
手動(dòng)升級(jí)#
升級(jí)過(guò)程往往會(huì)碰到很多問(wèn)題,尤其涉及到眾多第三方時(shí),處理起來(lái)尤為費(fèi)時(shí)費(fèi)力。此時(shí)建議可以嘗試直接 init 一個(gè)新的項(xiàng)目,然后把現(xiàn)有項(xiàng)目的 JS 代碼進(jìn)行手動(dòng)遷移。
本文檔貢獻(xiàn)者:sunnylqm(100.00%)#
總結(jié)
以上是生活随笔為你收集整理的fragment中文网_更新 · React Native 中文网的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java mongo 日期范围_java
- 下一篇: python生日提醒_python, 实