Massive updates with version 11 of Angular
Exciting times all around! Last week the Angular team shipped their latest major release, version 11.0.0 🎉 .This update includes some great improvements to the great Angular ecosystem, so let’s go over some what this means for you as an Ionic developer.
Before we dive into things, let’s go over how to update to this new release. For most projects you should just have to run
ng update and list the dependencies you’ll want to update:
ng update @angular/core @angular/cli npm install @ionic/angular-toolkit@latest
This updates the core libraries of Angular as well as the CLI and build tools. This also includes an update to the
@ionic/angular-toolkit which has a breaking change, making it a 3.0 release. So If you are not upgrading to version 11 of Angular, please stay on
With that out of the way, let’s dive into things!
One of the major goals between Angular’s 10.0 release and the 11.0 release was to reduce the overall backlog in the repo. Clearly the team was successful, because the changelog for the 11.0 release is huge! With close to 100 commits that include bug fixes and performance improvements, there’s a lot involved in this major release.
Many of these bug fixes are from older bugs that have been open for some time now. Since the Angular team was heads down getting Ivy out, there hasn’t been a lot of time to address some of these issues. But since Ivy shipped in version 9, the team has been able to refocus their efforts and finally address many outstanding issues.
Better Builds and Serving
When you think of major releases, the first thing you think of is CLI improvements, right? No? Just me? Well I for one welcome the latest improvements to the CLI. In previous releases of Angular, when running the dev server, the CLI would just print the output of the build process with very little formatting (outside of colors). You’re all probably used to seeing something like this:
Well, no more! It’s a small change, but now the Angular CLI will format things into a nice table. Really this is pretty small, but it’s nice and welcomed quality of life improvement:
But a better looking CLI is not all that’s in there. There’s also been significant improvements to the CLI’s build speeds. I recently shared a tweet showing off rebuilds with Angular and the speed is incredible:
[tweet https://twitter.com/mhartington/status/1328733943806517253 align=’center’]
Hot Module Replacement (HMR)
And finally, rounding out the CLI improvements, there’s also a brand new Hot Module Replacement (HMR) feature that is truly the icing on cake. HMR is a method of running your devserver where changes are applied without having to do a full rebuild of your app. This exists in other frameworks and now finally, Angular can join the “cool kids club” by providing a great HMR experience too.
Now HMR is great, but there was room for improvements with how it interacts with Ionic. Thankfully, this has already been fixed so we’re just waiting for a new patch release 🤞. BUT, we can at least take a look how HMR (with this patch applied) enhances the overall experience for developers.
To use HMR with developing Ionic apps, run
ionic serve -- --hmr.
Migration to ESLint
While not specific to version 11 of Angular, this is a major change in how we lint our projects. Linting is the process of analyzing your code for bugs, warnings, style and consistency changes, and more. In early 2019, TSLint was officially deprecated and the community centered around ESLint as it’s replacement. Since then, there’s been a lot of development in ESLint in order to support TypeScript as well as Angular. Now, we finally have TypeScript-ESLint and Angular-ESLint. This has been a huge community effort and I for one and thrilled to see the community adopt ESLint. While not provided by default with version 11 of Angular, you can opt into Angular-ESLint by running:
ng add @angular-eslint/schematics
It’s worth mentioning that if you make heavy use of projects like Codelyzer or custom TSLint rules, you’ll want to start planning your migration over to ESLint. For more information, check out the Angular-ESLint repo as well as the TypeScript-ESLint repo.
A better path forward
This blog post only covers what I think are some of the biggest updates, but there’s plenty more in the Angular Release Blog. What this release does highlight though is a clearer path forward to a better Angular. The Angular team has committed to providing a roadmap of features they want to work on, and many of these features have required changes to be made between version 9, 10, and now 11. While the timeline for these features are not set in stone, we can say that with these plans, Angular will have a great future. Let’s check back in roughly six months time and see what they work on 💪.