DEV Community

Cover image for Angular Ivy: a detailed introduction

Angular Ivy: a detailed introduction

Eugenio Lentini on December 10, 2019

Table Of Contents Slides Lingo Rendering architecture Virtual DOM Incremental DOM Enable Angular Ivy Enable Ivy in an exist...
Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen • Edited

I've noticed that in Angular 9 with Ivy enabled, the component definition is put in the static property ɵcmp rather than ngComponentDef.

This is also apparent in some of your compiled code examples.

Collapse
 
eugeniolentini profile image
Eugenio Lentini

Indeed, I have noticed as well, but during the Angular Connect 2019 in different cases that code has been called as compiled/generated.
I am waiting some feedback (if they will arrive) from Angular team members, but I guess that the clean and clear code is taken from some intermediate compilation steps and what we see if the final one emitted by the tsc.

I have checked before writing the post and the presentation and often they refer to that code (text(), etc) as compiled, generated, emitted by the Angular compiler.

I should try to see what happens with the ngc alone.

I keep you posted and then I update the post.
Thanks a lot for your reviewing work, appreciated :-)

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen

ngComponentDef was in Angular version 8 with Ivy enabled.

Thread Thread
 
eugeniolentini profile image
Eugenio Lentini

I have taken from the slides of the AC 2019, youtube.com/watch?v=S0o-4yc2n-8&li... min 2:00 on going

Thread Thread
 
layzee profile image
Lars Gyrup Brink Nielsen

This was presented 3 months ago. I first noticed it in RC0, but it might have changed before that.

Slides might say one thing, but code doesn't lie 😬

I have been experimenting a lot with Ivy and View Engine in different versions lately.

Thread Thread
 
eugeniolentini profile image
Eugenio Lentini

Totally agree that the code does not lie, I have considered what they have presented, I will add a small note to the post so people are aware that stuff are moving.

Once 9.0.0 will be out I will check write another post, but for the time being too afraid to see changes from one day to another.

Thanks a lot again for your support, it was I was looking for :-)

Thread Thread
 
layzee profile image
Lars Gyrup Brink Nielsen

Yeah, I will also be keeping an eye out. I'm thinking of creating a library for Angular library authors to detect Ivy vs. View Engine, production vs. development mode, testing vs. running app.

Thread Thread
 
eugeniolentini profile image
Eugenio Lentini

It would be awesome 👍

Thread Thread
 
eugeniolentini profile image
Eugenio Lentini

Hello,
in the meantime I have fixed the Uglify stuff and added the code compiled with the RC5 :-)

Thread Thread
 
layzee profile image
Lars Gyrup Brink Nielsen

RC6 now. (Will Ivy be a 2019 release?)

Thread Thread
 
eugeniolentini profile image
Eugenio Lentini

Well unless they sped up for the New Year’s Eve otherwise 2020 😊

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen • Edited

New finding: The ngComponentDef/ɵcmp key can be determined by importing ɵNG_COMP_DEF from @angular/core. So in version 8, ɵNG_COMP_DEF would evaluate to 'ngComponentDef' whereas it would evalute to 'ɵcmp' in Angular version 9.

There are similar key constants for directives, pipes, and Angular modules.

Collapse
 
eugeniolentini profile image
Eugenio Lentini

Really nice hint! I will have a look, I am working a post about compiler pipeline.

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen

Oh dear, I just discovered that this export was called ɵNG_COMPONENT_DEF in Angular version 8, but is renamed to ɵNG_COMP_DEF in Angular version 9 😔

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen

The Angular CLI uses Terser for minification, not Uglify.

Collapse
 
eugeniolentini profile image
Eugenio Lentini

I have to double check because during the Angular Connect 2018 they talked about Uglify plugin, may be they have changed the implmentation, thanks, much appreciated :-)

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen

Terser is listed as a dependency in Angular CLI's package.json and used in Angular builder.

In the past, they used uglify-es, but it became abandoned and a fork turned into Terser.

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen • Edited

Angular 9 is currently in RC5*
Angular stable is version 8.2.14.

Collapse
 
eugeniolentini profile image
Eugenio Lentini

Thanks, fixed it!

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen

Added note on the latest stable version of Angular. I think you got it confused with Angular CLI which is at 8.3.x.

Thread Thread
 
eugeniolentini profile image
Eugenio Lentini

Fixed that already with the previous.

Thread Thread
 
layzee profile image
Lars Gyrup Brink Nielsen • Edited

8.2.14, not 8.2.9 🙂

Collapse
 
xchanin profile image
Shannon Bruns • Edited

How can libraries be converted on the fly into Ivy compatible libraries during the build or installation process.

Is this something we can do now or is it something that will be available later?

Collapse
 
eugeniolentini profile image
Eugenio Lentini

Hello,
sorry for the delay, I am currently writing a post more focus on the compiler so I will investigate a bit better on the latest RC since things change quite quickly.

For the time being, citing the Compiler Model document on GitHub

ngcc can also be run as part of a code loader (e.g. for Webpack) to transpile packages being read from node_modules on-demand.

Collapse
 
xchanin profile image
Shannon Bruns

Sounds good. Thanks for the reply.

Collapse
 
angelnikolov profile image
Angel Nikolov

Hi Eugenio and thanks for the nice article!
I have a quick question though. Do you know if there's a way to use angular material precompiled in Angular 9? Right now ngcc recompiles all libraries on every build, which takes quite a bit of time, while I find it hard to believe there isn't a way to not do that for an official library which @angular/material is.
Any ideas?

Collapse
 
mrnoctv profile image
loctv

The new Ivy engineering has been driven by three main goals: three-shaking, locality and flexibility.

It should be tree-shaking, right? :)))

Anyway, great article, saves me a lot of time.

Collapse
 
eugeniolentini profile image
Eugenio Lentini

Yep, you are right, fixed the typo, thanks :-)

Collapse
 
rakiabensassi profile image
Rakia Ben Sassi

Great work Eugenio, thank you for sharing!