ng更新和npm更新有什么区别?

What is the difference between ng update and npm update?

有人可以解释一下 Angular 6 中的 ng updatenpm update 之间的区别吗?

ng update: 更新当前应用到最新版本。

就像 Web 和整个 Web 生态系统一样,Angular 也在不断改进。 Angular 在持续改进与高度关注稳定性和简化更新之间取得平衡。让您的 Angular 应用程序保持最新状态可以让您利用前沿的新功能以及优化和错误修复。

本文档包含的信息和资源可帮助您使 Angular 应用和库保持最新。

npm update:此命令会将列出的所有包更新为最新版本(由标签配置指定),尊重 semver。

它还会安装缺少的包。与安装包的所有命令一样,--dev 标志也会导致处理 devDependencies。

如果指定了 -g 标志,此命令将更新全局安装的包。

如果未指定包名称,将更新指定位置(全局或本地)中的所有包。

从 npm@2.6.1 开始,npm 更新将只检查顶级包。 npm 的早期版本还会递归地检查所有依赖项。要获得旧行为,请使用 npm --depth 9999 更新。

从 npm@5.0.0 开始,npm 更新将更改 package.json 以将新版本保存为所需的最低依赖项。要获得旧行为,请使用 npm update --no-save。

来源:
https://github.com/angular/angular-cli/wiki/update
https://docs.npmjs.com/cli/update

ng updatenpm update

做得更多

ng update 将更新您的依赖项(与 npm update 相同),但除此之外,它 还可以 运行 update-schematics:库作者可能会在更新过程中包含此类示意图以自动更新您的代码(即您的打字稿)文件:即他们可以直接在您的代码中修复重大更改。

来自ng-update: Library Developers

Libraries are responsible for defining their own update schematics. The ng update tool will update the package.json, and if it detects the "ng-update" key in package.json of the library, will run the update schematic on it (with version information metadata).

If a library does not define the "ng-update" key in their package.json, they are considered not supporting the update workflow and ng update is basically equivalent to npm install.

更新完成后,您的 package.json 文件将包含更新版本,软件包安装在 node_modules 文件夹中,您的 source-code 可能已被更改update-schematics。所以现在是使用版本控制系统检查更改和测试应用程序的好时机。