npm检查依赖最新版本并升级

目录

使用 npm-check-updates 检查依赖并升级。

1.安装 npm-check-updates

1
$ npm install npm-check-updates -g

2.查看package.json中依赖的最新版本

1
$ ncu

执行结果:

1
2
3
4
5
6
7
8
9
10
11
Using /Users/xxx/package.json
⸨░░░░░░░░░░░░░░░░░░⸩ ⠸ :
mobx ^3.3.1 → ^5.5.0
mobx-react ^4.2.2 → ^5.2.8

The following dependencies are satisfied by their declared version range, but the installed versions are behind. You can install the latest versions without modifying your package file by using npm update. If you want to update the dependencies in your package file anyway, run ncu -a.

antd ^3.1.2 → ^3.10.1
node-sass ^4.6.1 → ^4.9.3

Run ncu with -u to upgrade package.json

3.更新package.json依赖到最新版本

1
$ ncu -a 

4.执行npm install 完成新依赖安装升级

1
$ npm install

5.完成升级

注意前端发展日新月异,版本间有时差距较大,不建议做无准备的升级。