When I upgraded from Angular 8 to 9, the compile time increased by more than 3 times and also, I used the Scss style template but after upgrading, when I generate component, it creates a css file for the component.
I checked angular.json and the config is "styleext": "scss" is there any solution for these issues?
The Angular ahead-of-time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.
JIT downloads the compiler and compiles code exactly before Displaying in the browser. AOT has already complied with the code while building your application, so it doesn't have to compile at runtime. Loading in JIT is slower than the AOT because it needs to compile your application at runtime.
When you use the Angular AOT compiler, you can control your app compilation in two ways: By providing template compiler options in the tsconfig. json file. By specifying Angular metadata.
FIX
Turn off AOT in the angular.json -> search the first occurrence (default build config) of aot and change from true to false
The production build should still use AOT, since the production build config further down has AOT still turned on.
Explanation
As part of migration from Angular 8 > 9 they simply decided to enable the AOT (Ahead Of Time) compilation not only for --prod builds, but also for regular builds (+watch/serve), with the argument that AOT is now much faster with the new Ivy compiler. They haven't thought this through IMO, because this caused my watch/serve builds to increase from 1 second to 30 seconds.
Further reading: https://v9.angular.io/guide/ivy
The correct definition is through style and not styleext.
Create a new project (ng new demo
) and choose SCSS and have a look how it is defined there.
I got same issue when I migrated Angular 4 to Angular 9. Then, I disabled Ivy
in Angular 9. From Angular 9, Ivy
is set to true
as default which was not in Angular 8.
Go to tsconfig.json
and disabled Ivy
mode.
{
...
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableIvy": false
}
...
}
Note: This is temporary solution only. Maybe, in the next version, this issue will be handled.
I see only temporary half-solutions so I am going to provide more ligh on this matter.
I met these problems on few projects and it is probably due to how your app is written. In my case there were problems with compiling scss and wrong NgModules management. Unfortunately you cannot show us whole application I guess.
I recommend a few things:
Things like that happen when the application grows and noone pays attention to this, but many of those things are easily to miss. People then say that Angular is bad and move to other libraries/frameworks, but it is just our misunderstanding of Angular genius and complexity that limits us. Good luck! :-)
Make sure in your angular configuration is similar to as below
"@schematics/angular:component": {
"style": "scss",
"prefix": "cfs"
},
I think styleext
changed to style
in angular 9
there might be some configuration issue, in angular, the compiler time should be drastically reduced.
you can look into this PR, i migrated and it wend well https://github.com/aniruddhadas9/candifood-ui/pull/15
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With