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

查看:87
本文介绍了通过阅读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,所以不会这样做。
无论您使用何种服务器,最新版本: 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 @< version> 例如 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

使用yarn

最新版本,同时仍然遵守package.json中的semver 纱线升级反应

最新版本,与您使用的版本无关:纱线升级react @ latest

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

https://yarnpkg.com / lang / zh-CN / docs / cli / upgrade /

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

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