React-Native 十:版本升级

更新版本的React Native将会让你访问更多的APIs, 这样我们可以去使用更多的APIs,视图Views,以及开发者工具以及其他一些好用的东西。浏览版本更新日志就会发现整体FB官方开发进度还是非常紧张的,这样就很容易导致旧版本会出现不能用的情况,后期可能会出现不可预料的情况,这边建议大家尽量更新最新正式版本
我们大家都知道一个React Native项目使用Android项目,iOS项目和JavaScript项目三部分进行组成的,而且三者都关联打包在npm包内的,所以该项目版本进行更新是比较繁琐的。下面我来给大家讲解一下React Native项目的升级步骤。
一、查看当前版本
pengchengxiang@ubuntu:~/AwesomeProject$ react-native --version
react-native-cli: 0.2.0
react-native: 0.22.2
二、查看最新的版本
pengchengxiang@ubuntu:~/AwesomeProject$ npm info react-native
{ name: 'react-native',
  'dist-tags': { latest: '0.25.1', next: '0.26.0-rc' },
  versions:
   [ '0.0.0',
     '0.0.5',
      ... ... 
     '0.24.1',
     '0.25.0-rc',
     '0.25.1',
     '0.26.0-rc' ],
  maintainers:
  ... ... 
  dist:
   { shasum: '4177e70e56281cec8fb5fe76218bf6606eeb34b8',
     tarball: 'https://registry.npmjs.org/react-native/-/react-native-0.25.1.tgz' },
  directories: {} }
三、升级依赖的版本
pengchengxiang@ubuntu:~/AwesomeProject$ npm install --save [email protected]

> [email protected] install /home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/bufferutil
> node-gyp rebuild

make: Entering directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/bufferutil/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
  SOLINK_MODULE(target) Release/obj.target/bufferutil.node
  COPY Release/bufferutil.node
make: Leaving directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/bufferutil/build'

> [email protected] install /home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/utf-8-validate
> node-gyp rebuild

make: Entering directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/utf-8-validate/build'
  CXX(target) Release/obj.target/validation/src/validation.o
  SOLINK_MODULE(target) Release/obj.target/validation.node
  COPY Release/validation.node
make: Leaving directory `/home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/ws/node_modules/utf-8-validate/build'

> [email protected] postinstall /home/pengchengxiang/AwesomeProject/node_modules/react-native/node_modules/yeoman-generator/node_modules/cross-spawn/node_modules/spawn-sync
> node postinstall

npm WARN optional dep failed, continuing [email protected]
[email protected] node_modules/react-native
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
提示1:如果在安装的过程中,报错如下
pengcx@pengcx-Ubuntu:~/ReactNativeWorkspace/AwesomeProject$ npm install --save [email protected]
npm ERR! tar.unpack error reading /home/pengcx/.npm/babel-runtime/6.6.1/package.tgz
npm ERR! tar.unpack error reading /home/pengcx/.npm/babel-runtime/6.6.1/package.tgz
npm ERR! tar.unpack error reading /home/pengcx/.npm/object-assign/4.1.0/package.tgz
npm WARN optional dep failed, continuing [email protected]
npm ERR! tar.unpack error reading /home/pengcx/.npm/babel-runtime/6.6.1/package.tgz
npm ERR! tar.unpack error reading /home/pengcx/.npm/path-exists/1.0.0/package.tgz
npm WARN optional dep failed, continuing [email protected]
npm ERR! Linux 3.13.0-85-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "--save" "[email protected]"
npm ERR! node v4.4.3
npm ERR! npm  v2.15.1
npm ERR! 0-byte tarball
npm ERR! Please run `npm cache clean`
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR!     /home/pengcx/ReactNativeWorkspace/AwesomeProject/npm-debug.log
处理:npm cache clean
四、更新你项目的template文件
新的npm包会包含更新在运行react-nativeinit命令生成的一些动态文件,例如init创建项目的时候会生成iOS和Android的子项目,我们可以通过以下的命令进行获取最新的代码:
pengchengxiang@ubuntu:~/AwesomeProject$ react-native upgrade
Upgrading project to react-native v0.25.1
Be sure to read the release notes and breaking changes:
https://github.com/facebook/react-native/releases/tag/v0.25.0
 conflict .gitignore
? Overwrite .gitignore? overwrite
    force .gitignore
identical .watchmanconfig
   create .buckconfig
identical ios/AwesomeProject/AppDelegate.h
identical ios/AwesomeProject/AppDelegate.m
identical ios/AwesomeProject/Base.lproj/LaunchScreen.xib
identical ios/AwesomeProject/Images.xcassets/AppIcon.appiconset/Contents.json
identical ios/AwesomeProject/Info.plist
identical ios/AwesomeProject/main.m
 conflict ios/AwesomeProjectTests/AwesomeProjectTests.m
? Overwrite ios/AwesomeProjectTests/AwesomeProjectTests.m? overwrite
    force ios/AwesomeProjectTests/AwesomeProjectTests.m
identical ios/AwesomeProjectTests/Info.plist
identical ios/AwesomeProject.xcodeproj/project.pbxproj
identical ios/AwesomeProject.xcodeproj/xcshareddata/xcschemes/AwesomeProject.xcscheme
 conflict android/build.gradle
? Overwrite android/build.gradle? overwrite
    force android/build.gradle
identical android/gradle.properties
identical android/settings.gradle
   create android/app/BUCK
 conflict android/app/build.gradle
? Overwrite android/app/build.gradle? overwrite
    force android/app/build.gradle
 conflict android/app/proguard-rules.pro
? Overwrite android/app/proguard-rules.pro? overwrite
    force android/app/proguard-rules.pro
identical android/app/src/main/java/com/awesomeproject/MainActivity.java
To run your app on iOS:
   cd /home/pengchengxiang/AwesomeProject
   react-native run-ios
   - or -
   Open /home/pengchengxiang/AwesomeProject/ios/AwesomeProject.xcodeproj in Xcode
   Hit the Run button
To run your app on Android:
   Have an Android emulator running (quickest way to get started), or a device connected
   cd /home/pengchengxiang/AwesomeProject
   react-native run-android
它会检查你的文件,对比最新版本,然后进行如下几个操作:
     如果是新添加的文件,会进行直接创建
     如果更新的文件和当前项目的文件是一样的,就会直接忽略跳过
     如果更新的文件和当前项目的文件不同,有冲突的情况,会让我们进行选择是保留原来的文件还是用更新的文件覆盖,这个要看实际情况了。


你可能感兴趣的:(Install,npm,Upgrading,react-upgrade,react-natvie)