我在现有项目中使用 angular-cli 1.0.4,我想将版本更新到 1.2.4。使用 npm 卸载旧版本并更新到新版本并影响我现有项目的最佳方法是什么?这会更新 package.json 文件中的版本。
最佳答案
将 your angular cli
更新到 any
版本的指南
更新 2018 年 10 月 23 日引用:how to update an app when ng cli and angular change version best practice :
If you are on Angular CLI version 6+ just run
ng update
then follow the command line instructions. Also checkout this guide Updating your Angular projects
最近我正在将我的项目从 1.0.4
升级到 1.3.0-beta
,但是这同样适用于任何 Angular CLI 版本。
因此,首先只需安装要将项目升级为 https://github.com/angular/angular-cli#updating-angular-cli 的 angular cli是说:
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@<put exact version here>
升级步骤:
- 创建一个
新空白
项目,如ng new project-name
您可以命名您的新“ Playground ”项目
与您的旧项目
完全一样,但请确保它位于与当前项目不同的文件夹中。 将您的
app
文件夹从您的旧项目
复制/替换到您刚创建的新项目
将所有自定义更改引入项目中的所有其余文件:
3a.将旧项目中所有与项目相关的 npm 包放入package.json
(使用比较工具)新旧package.json
的区别> 将只是@anngular/cli@version
及其相关的包版本,如karma
等
3b.使用比较工具(请参阅下面的更新)确保您从所有 cli 相关文件(例如.angular-cli.json
,.gitignore
,index.html
,src/polyfills.ts
,src/main.ts
,src/test.ts
, 等运行
npm install
或yarn
- 测试所有
npm 脚本
:
5a - 运行ng serve
以确保其正常工作,如果不能修复错误
5b - 运行ng build
以确保其正常工作,如果不能修复错误
5c - 运行ng lint
以确保其正常工作,如果不能修复错误
5d - 运行ng test
以确保其正常工作,如果不能修复错误(该步骤中的 here is an error I’ve being caught)
5e - 测试您的应用所依赖的所有其他npm 脚本
。
完成上述所有操作后,您可以删除或归档旧项目
以防万一,并从那时起继续新项目
。
UPDATE: you also can use this angular-cli-diff to find out what is the difference between the versions e.g https://github.com/cexbrayat/angular-cli-diff/compare/1.4.0...1.5.0 (see the
Files changed
tab)
所以 angular-cli-diff你这样做:
- 区分 cli 版本,例如:https://github.com/cexbrayat/angular-cli-diff/compare/1.4.0...1.5.0
- 点击
文件已更改
标签 - 将更改应用到您当前的项目。
npm install/yarn
- 如上所述测试步骤
5(a-e)
中的更改
关于angular - 在现有项目中更新 Angular CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45416430/