18

In Angular CLI, ng serve uses JiT and the flag --aot is required in order to use AoT compilation.

Is it possible to make that ng serve uses AoT by default and JIT is only used when --aot=false flag is passed?

acalvo
  • 375
  • 1
  • 3
  • 8

2 Answers2

37

Edit: starting with angular 9, aot compilation is enabled by default in development environment (see documentation)

In angular 6, you can specify default options for the serve target, so you can add aot: true in that section and by default ng serve will use aot

"serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "project:build",
        "aot": true
      },
      "configurations": {
David
  • 33,444
  • 11
  • 80
  • 118
  • 1
    Just what I was looking for. Thanks! – acalvo Jul 05 '18 at 10:55
  • I am not sure if this is true, angular 9 enabled it by default for builds but not for the serve command: https://github.com/angularexample/angular-9-example-app/blob/master/angular.json – Jay Ordway Jun 24 '20 at 07:46
5

Not directly an answer to your question, but rather an alternative way of achieving the same result. In your package.json file, you can add a custom script which compile with AoT.

...
"scripts": {
    "aot": "ng serve --aot"
  },
...

Then you can run the command npm aot.

John
  • 10,165
  • 5
  • 55
  • 71