is there a way to use AOT with angular cli?
I've installed the modules (@angular/compiler @angular/compiler-cli) and when I type ngc -p scr it creates the ngFactory.ts files and compiles it to dist/tsc-out (angular cli default in tsconfig)
not sure how to proceed from here :)
Cheers
Han
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.
The Angular CLI can create a new Angular project and it will handle the webpack configuration.
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.
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.
This is the default since Angular 9. When you run the ng build (build only) or ng serve (build and serve locally) CLI commands, the type of compilation (JIT or AOT) depends on the value of the aot property in your build configuration specified in angular.json. By default, aot is set to true for new CLI applications.
Angular offers two ways to compile your application: Just-in-Time (JIT), which compiles your application in the browser at runtime. This was the default until Angular 8. Ahead-of-Time (AOT), which compiles your application and libraries at build time.
The @ngtools/webpack provides AOT Plugin and loader for Webpack which shares the context with other loaders/plugins. Run the below command to install NPM package @ngtools/webpack. The below steps depicts the configuration of @ngtools/webpack in Angular application. @ngtools/webpack compiles the typescript files in application.
All recent beta versions of the Angular CLI support AoT via the following:
ng serve --aot
ng build --aot
#and of course
ng build --prod --aot
Note: As of Angular CLI 1.0.0-beta.28 (released February 1st, 2017), --aot
is on by default if --prod
is specified.
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