通过阅读 package.json 升级 React 版本及其依赖项 [英] Upgrading React version and it's dependencies by reading package.json

查看:74
本文介绍了通过阅读 package.json 升级 React 版本及其依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的项目,它有 react@15 和所有它的依赖项.但现在我必须升级到 react@16 以及它的依赖项.现在,问题是 - 有很多依赖项,识别每个依赖项的版本非常耗时.

I have an existing project, which has react@15 and all it's dependencies according to that. But now I have to upgrade to react@16 along with it's dependencies. Now, the problem is - there are a lot of dependencies and it is very time consuming to identify version of each dependency.

所以,我想知道是否有一种方法可以升级 React 的版本及其在 package.json 中提到的依赖项,而无需手动修改 package.json 文件.

So, I was wondering if there was a way where I could upgrade the versions of React and it's dependencies mentioned in package.json, without manually modifying the package.json file.

推荐答案

使用 npm

最新版本同时仍然尊重 package.json 中的 semver:npm update <package-name>.所以,如果你的 package.json 说 "react": "^15.0.0" 并且你运行 npm update react 你的 package.json 现在会说 "react": "^15.6.2"(当前最新版本的 react 15).

Latest version while still respecting the semver in your package.json: npm update <package-name>. So, if your package.json says "react": "^15.0.0" and you run npm update react your package.json will now say "react": "^15.6.2" (the currently latest version of react 15).

但既然你想从反应 15 到反应 16,那是行不通的.最新版本,无论您的 semver 是什么:npm install --save react@latest.

But since you want to go from react 15 to react 16, that won't do. Latest version regardless of your semver: npm install --save react@latest.

如果您想要特定版本,请运行 npm install --save react@ 例如npm install --save react@16.0.0.

If you want a specific version, you run npm install --save react@<version> e.g. npm install --save react@16.0.0.

https://docs.npmjs.com/cli/install

使用纱线

最新版本同时仍然尊重你的 package.json 中的 semver:yarn upgrade react.

不管你的 semver 是什么的最新版本:yarn upgrade react@latest.

Latest version regardless of your semver: yarn upgrade react@latest.

https://yarnpkg.com/lang/en/docs/cli/upgrade/

这篇关于通过阅读 package.json 升级 React 版本及其依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆