English 中文(简体)
Angular 8 - Ivy Compiler
  • 时间:2024-09-17

Angular 8 - Ivy Compiler


Previous Page Next Page  

Ivy Compiler is the latest compiler for Angular apppcation released by Angular Team. Currently, Angular is using View Engine compiler to compile Angular apppcation.

In general, Angular compiler has two options to compile an apppcation.

Just In Time (JIT) Compiler

In Just In Time (JIT) compilation, the compiler will be bundled along with the apppcation and send to the browser. Angular apppcation will be compiled in the browser and run just before the execution of apppcation.

Eventhough JIT provides certain advanced feature, JIT slows down the compilation and also the app bundle will be double the size produced by AOT compiler as it includes compiler as well.

Ahead Of Time (AOT) Compiler

In AOT compilation, the compiler will emit optimised code ready to run inside the browser without any addition step. It will reduce the size of the bundle as well as reduce the compilation time and startup time of the apppcation.

Advantages of Ivy Compiler

Ivy Compiler is the optimised and advanced compiler for Angular. As of Angular 8, it is not yet complete even though it is useable at this stage. Angular Team is recommending the developer to use it in Angular 8.

The main advantages of Ivy Compiler are as follows −

    Optimised code.

    Faster build time.

    Reduced bundle size.

    Better performance.

How to use Ivy?

Ivy Compiler can be used in Angular 8 apppcation by changing the project setting as specified below −

Open angular.json and set the aot option (projects -> -> architect -> build -> configurations -> production) of the project to true.


{
   "projects": {
      "my-existing-project": {
         "architect": {

            "build": {
               "options": {
                  ...
                  "aot": true,
               }
            }
         }
      }
   }
}

Open tsconfig.app.json and set enableIvy to true under angularCompilerOptions.


{ 
   ... 
   "angularCompilerOptions": { 
      "enableIvy": true 
}

Compile and run the apppcation and get benefited by Ivy Compiler.

Advertisements