Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use ahead-of-time compiler with angular cli webpack

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

like image 618
Han Che Avatar asked Aug 26 '16 13:08

Han Che


People also ask

What is ahead of time compiler in Angular?

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.

Does Angular CLI use Webpack?

The Angular CLI can create a new Angular project and it will handle the webpack configuration.

How JIT and AOT works in Angular?

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.

What is ahead-of-time compiler in angular?

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.

What is the default type of compilation in angular 9?

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.

What is ahead of time in angular JIT?

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.

How to use @ngtools/Webpack in angular?

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.


1 Answers

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.

like image 104
Brocco Avatar answered Sep 22 '22 17:09

Brocco