Angular Version 11 Is Out!
Let’s Carefully Analyze The New Features
Version 11 of angular is here and we’ve got some interesting updates to check out. In this short article I’ll walk you through the most significant new features you need to know about and point out why you may or may not want to update your project.
I’ll start with a warning, if you have not yet updated your version of angular cli to the latest v11, you may not be able to create new angular projects using
ng new . To fix this simply run:
npm install -g @angular/cli@latest
This will get you running the latest version of angular cli and you should be able to create new projects just fine now, the issue seems to stem from the death of the default linting system in angular which I will talk about in a little bit. Now let’s talk features! 🎉
BETTER COMMAND-LINE FORMATTING
This is a huge one. Developers working in angular usually spend more time in the command-line than react due to the beloved
ng cli so angular 11 comes with some serious improvements in this area.
You will now get some neat tables drawn to order your compiled components allowing you to make quick size comparisons between your files. This table structure can be seen in many other places in the new cli as well. Personally, I’d update just for this feature.
AUTOMATIC FONT INLINING
This might very well be biggest improvement in this version of angular, although there is a bit of argument around whether or not it helps at all.
Angular now downloads fonts being used in the project and adds them to the build files. Take note that this only happens when you build for production, which can be done using:
ng build --prod
Clink the above image and have a look at the changes that angular makes to the code that imports the font Roboto imported from fonts.google.
I think this is a pretty impressive feature overall and adds just a small improvement to load times of angular programs.
Warning:: This feature can cause issues with some fonts when you update an old angular project to CLI v11. You can work around this by turning it off for your project by adding the code below to the package.json file:
If the issue persists you might want to check this issue.
HOT MODULE RELOADING
Hot module reloading now allows angular 11 to refresh the page content when you edit your code without ever needing to refresh the website. This is definitely angular trying to catch up to react but it’s definitely a welcome change for the small development time it will save you.
This feature is disable by default but thankfully can easily be enabled on an angular v11 project by running:
ng serve --hmr -o
This is what I see when I update a component on my website now, beautiful
Hopefully angular decides to do work in the future to allow us to not need to manually restart the compilation process when we import new components as well.
And that’s it for the big changes, I will now talk about whether you should update your project to the new version.
You SHOULD TOTALLY Use v11 For New Projects
When creating new projects using a version of Angular CLI earlier than v11 you might get an error associated with the deprecation of TSLint.
The problem appears to be connected to npm. The workaround I have found thus far involves changing the main
ng package manager to yarn instead of npm. You can use the following command:
ng config -g cli.packageManager yarn
You can either do that if you really wanna use an older version of angular or just update to the latest. You might want to highlight this section for the next time you want to create a new angular app I would suggest the latest version of the CLI for new apps though.
Enjoying this article so far? Come hang out with me on Twitter, I evaluate new technologies on a regular to see if they will be helpful and save time for your projects 😊.
Should You Update Old Projects To Angular V11
There are a few things for anyone that already has a project in Angular v10 or earlier to consider for updating, particularly for large projects;
- Auto Font Inlining → If you’re using inlined fonts in your project rest assured Angular can make breaking changes when you build for production due to the new Font Inlining Feature. The feature is meant to improve load time by optimizing external fonts in your project. The problem is that browsers usually cache common fonts anyway and so this might not have a significant effect on your program if it uses common fonts like Roboto, Helvetica etc. These have high chances of already being cached in the user’s browser. If you’re still on the edge about updating for this feature, I would suggest only doing so if you app using a lot of rare fonts in it.
- Webpack 5 Support → This is yet another feature in angular v11 that might be useful for people with big apps built on angular. Particularly the Tree-Shaking feature in Web Pack which allows the build process to automatically remove unused parts of your code such as methods and will overall reduce the size of your production build. If that is something you have been struggling with, you will definitely want to look further into this update. Check out this link for more information.
You will need to add Webpack 5 to your resolutions in your package.config and switch to to yarn as you package manager for this to work.
I would suggest testing this out in a separate project anyway just to get a feel for how these changes could affect you project’s builds before doing it in an actual application.
- Internet Explorer Support → Honestly, we all knew this one was coming. For anyone that has still been developing apps for legacy Internet Explorer versions, the end is here. Support, in Angular 11 has been removed for versions older than 11. (Get it? ) Anyway, yeah, that happened. Honestly, I didn’t even know there was an IE for mobile but that lost support as well. So for the two developers that were still targeting those platforms, you definitely don't wanna update. Or maybe you wanna update and stop supporting those browsers anyway.
Finally, I don’t think ng V11 comes with enough changes for the kinds of projects that I work on to update, so I’m not gonna update any already live project. I will be using the new version for all new projects though.
Thanks a lot for checking out this article and let me know what you think about the changes in the comments, will you be updating and why? Cheers for now. 🤗