angular - 在现有项目中更新 Angular CLI

标签 angular migration upgrade angular-cli

我在现有项目中使用 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>

升级步骤:

  1. 创建一个新空白项目,如ng new project-name您可以命名您的新“ Playground ”项目与您的旧项目完全一样,但请确保它位于与当前项目不同的文件夹中。
  2. 将您的 app 文件夹从您的旧项目复制/替换到您刚创建的新项目

  3. 将所有自定义更改引入项目中的所有其余文件:
    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, 等

  4. 运行 npm installyarn

  5. 测试所有 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你这样做:

  1. 区分 cli 版本,例如:https://github.com/cexbrayat/angular-cli-diff/compare/1.4.0...1.5.0
  2. 点击文件已更改标签
  3. 将更改应用到您当前的项目。
  4. npm install/yarn
  5. 如上所述测试步骤 5(a-e) 中的更改

关于angular - 在现有项目中更新 Angular CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45416430/

相关文章:

javascript - 收到两个不同的服务调用后显示页面

javascript - 简单的 Angular 2 应用程序出现 "Potentially unhandled rejection"错误

ruby-on-rails - rake 数据库 :schema:dump doesn't provide data migration info - is there an automated way to get this?

svn - 谷歌代码 svn 迁移

ruby-on-rails - 分区数据库表的 Rails 迁移索引名称太长

java - Grails3:AuthRoleController中的java.lang.Boolean hasErrors()的返回类型与grails.artefact.Controller中的 boolean 值不兼容。

c# - 等效于 DbContext 上的 ObjectContext.AddObject(entityName, entity)

javascript - 在 Angular JS 中删除下划线并添加财政年度

angular - 结构指令的上下文未更新

jQuery 1.9.1 $.event.handle.apply 替代方案