简体   繁体   English

如何使用 angular cli 升级 angular 的次要版本

[英]How to upgrade minor version of angular using angular cli

This is a simple question but I'm struggling to find the answer via Google...这是一个简单的问题,但我正在努力通过谷歌找到答案......

I have an angular 4 project (created using angular cli) and would like to make use of http interceptors that have just been released in 4.3.我有一个 angular 4 项目(使用 angular cli 创建)并且想使用刚刚在 4.3 中发布的 http 拦截器。

How do I upgrade to this minor release using angular cli?如何使用 angular cli 升级到这个次要版本?

In my Angular CLI project I use npm update to update my dependencies.在我的 Angular CLI 项目中,我使用npm update来更新我的依赖项。 With npm outdated , you can see all outdated dependencies.使用npm outdated ,您可以查看所有过时的依赖项。


Update June 2018 2018 年 6 月更新

If you're using Angular CLI version 6+, you can use the new ng update <packagename> command to update your dependencies.如果您使用的是 Angular CLI 版本 6+,则可以使用新的ng update <packagename>命令来更新您的依赖项。

⚠️ This will update to the newest major version. ⚠️ 这将更新到最新的主要版本。 If you don't want that stick with npm update .如果你不想坚持使用npm update ⚠️ ⚠️

https://angular.io/guide/updating https://angular.io/guide/update

For simple updates, the CLI command ng update is all you need.对于简单的更新,您只需要 CLI 命令ng update Without additional arguments, ng update lists the updates that are available to you and provides recommended steps to update your application to the most current version.如果没有额外的参数, ng update列出可供您使用的更新,并提供将您的应用程序更新到最新版本的推荐步骤。

Major version angular updates should be done with ng update .主要版本的角度更新应该使用ng update完成。

npm update for updating angular minor/patch versions has a downside: it will also update other unrelated packages.用于更新角度次要/补丁版本的npm update有一个缺点:它还会更新其他不相关的包。

You can use npm-check-updates to update just specific packages and you can choose to target patch/minor/major versions.你可以使用npm-check-updates来更新特定的包,你可以选择定位补丁/次要/主要版本。

This command will update all angular package minor (and patch) versions (but it will keep the major versions):此命令将更新所有 angular 包次要(和补丁)版本(但会保留主要版本):

npx npm-check-updates --upgrade --target "minor" --filter "/@angular.*/"

That command gives you a preview of the new versions and updates the package.json accordingly:该命令为您提供新版本的预览并相应地更新 package.json:

在此处输入图片说明

Afterwards you can run npm install .之后你可以运行npm install

In some cases ng update doesn´t update the angular core dependencies with minor version updates.在某些情况下,ng update 不会通过次要版本更新来更新 angular 核心依赖项。

I´ve faced a case trying to update from Angular 6.0.0 to 6.1.0, and isn´t worked.我遇到了一个尝试从 Angular 6.0.0 更新到 6.1.0 的案例,但没有成功。

I solved this only doing the steps:我只按照以下步骤解决了这个问题:

  1. Delete project node_modules directory删除项目 node_modules 目录
  2. Change manually in the package.json all the angular core dependencies libraries:在 package.json 中手动更改所有 angular 核心依赖库:

... common, compiler, compiler-cli, core, forms, http ... platform-browser, platform-browser-dynamic, router ... 通用、编译器、编译器-cli、核心、表单、http ... 平台浏览器、平台浏览器动态、路由器

like this: .像这样: 。 . . . . "dependencies": { "@agm/core": "~1.0.0-beta.3", "@angular/animations": "^6.0.9", "@angular/cdk": "^6.4.0", "@angular/cli": "^6.2.9", "@angular/common": "^6.1.x", "@angular/core": "^6.1.x", "@angular/forms": "^6.1.x", "@angular/http": "^6.1.x", "dependencies": { "@agm/core": "~1.0.0-beta.3", "@angular/animations": "^6.0.9", "@angular/cdk": "^6.4.0" , "@angular/cli": "^6.2.9", "@angular/common": "^6.1.x", "@angular/core": "^6.1.x", "@angular/forms": "^6.1.x", "@angular/http": "^6.1.x",

See in the devdependencies for compiles, compiler-cli too在 devdependencies 中查看编译,compiler-cli 也是

  1. Run npm install to rebuild node modules.运行 npm install 来重建节点模块。
  2. After this we have the result of ng --version cli command from 6.0.0 to 6.1.10在此之后,我们有 ng --version cli 命令的结果从 6.0.0 到 6.1.10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM