How do I enable Ivy for Angular 8 or 9?

2020-03-24 15:33发布

问题:

How do I enable Ivy on a Angular 8 or 9 project?

Ivy is the upcoming render engine for Angular which introduces a lot of nice features without changing the actual code base of Angular projects.

回答1:

source and more information go though this

Reference : https://dzone.com/articles/how-to-upgrade-angular-packagesenable-ivy-compiler

you can auto upgrade

npm i -g @angular/cli@latestng update

or in your tsconfig.json file update this

{
  "compilerOptions": {
    "module": "esnext",
    // ...
  },
  "angularCompilerOptions": {
    "enableIvy": true,
    "allowEmptyCodegenFiles": true
  }
}

then your angular.json file

{
  "projects": {
    "your-project": {
      "architect": {
        "build": {
          "options": {
            ...
            "aot": true,
          }
        }
      }
    }
  }
}


回答2:

use this official guide.

Using Ivy in a new project :

To start a new project with Ivy enabled, use the --enable-ivy flag with the ng new command:

ng new shiny-ivy-app --enable-ivy

The new project is automatically configured for Ivy. Specifically, the enableIvy option is set to true in the project's tsconfig.app.json file.

Using Ivy in an existing project :

To update an existing project to use Ivy, set the enableIvy option in the angularCompilerOptions in your project's tsconfig.app.json.

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

AOT compilation with Ivy is faster and should be used by default. In the angular.json workspace configuration file, set the default build options for your project to always use AOT compilation.

{
  "projects": {
    "my-existing-project": {
      "architect": {
        "build": {
          "options": {
            ...
            "aot": true,
          }
        }
      }
    }
  }
}

To stop using the Ivy compiler, set enableIvy to false in tsconfig.app.json, or remove it completely. Also remove "aot": true from your default build options if you didn't have it there before.



标签: angular