Updating angular-cli Projects
I absolutely love angular-cli and for me it’s the go to tool for any angular project. The team around it is doing a great job, and I’m very thankful but:… things to consider …
The angular-cli is under heavy development and moving it into the @angular/cli package lead to the removal of several features, that they either don’t want to maintain within angular-cli or want to rewrite “better” in the next version:
“npm install -g @angular/cli vs angular-cli”
The project was now moved into the core repository of angular, but the “old” package is still there. If you want to keep things simple for the moment, you can just install angular-cli, ignore the deprecated message and continue to use it for a while. But some day you’ll have to move on.
ng init, ng update
Running ng init with the proper parameters guided you through a update wizard where you could choose to overwrite, diff or ignore a new file. In combination with git and vscode/git-view, this was the quickest way for me to update a project. According to github the team decided to remove this with beta31. If you still want to use it, you can just downgrade to beta30: “npm -g install @email@example.com”
Tip: If you have an old project you may run into a browser error “Unhandled Promise rejection: Failed to load app.component.html ; Zone: <root> ; Task: Promise.then ; Value: Failed to load app.component.html” Removing the node_modules folder and running npm install again fixt that for me.
Alternative update path:
Alternatively to “ng init” I found this way very practical:
- npm uninstall -g angular-cli
- npm install -g @angular/cli
- Create new project vanilla project with “ng new” and the parameters of your current project (--prefix xyz --routing true).
- Delete .git, assets, src/styles.css and src/app in your new vanilla project
- Move .git and the other folders from your current folder into the vanilla project
- Open Visual Studio Code GIT view
- Go through all changes and either “fix/merge” them or revert them (you can also revert a missing file)
- Test it :-)
- Commit the merged/updated files
This also works great with changes to package.json, as you can see them in the diff view. It also works if you added any file that you forgot to take over from your former project, as git will show you missing files. Just don’t commit before you are happy with the upgrade-merged version.
ng github-pages:deploy gone
As a side note, also the command to deploy a project to github pages was remove. But there is an alternative project that gives you the same functionality:
angular-cli-ghpages - :shipit: Wrapper around gh-pages, made for angular-cli users. Publish to any gh-pages branch on…github.com
npm install -g angular-cli-ghpages
ng build --prod --base-href "https://USERNAME.github.io/REPOSITORY/"