1

Starting from angular 9, angular started using a new renderer engine called IVY and as its document says the built code will look same in dev and prod environment and easy to debug, is it still required to pass --prod and --aot option while building code

old build command

ng build --aot --prod

is not it new command should look like

ng build //for both prod and dev build

or only the --prod option is required for the prod build

user2846469
  • 2,072
  • 3
  • 18
  • 32
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132

3 Answers3

4

Aot was never required, it was default set to on in the production build, and off in development. Now aot is standard on for all environments, because of the speed improvements. So for a development build you do:

ng build

and for a production build

ng build --prod

You can check your angular.json file to see which setting does what. The --prod did more than just turning on the ahead of time compiler. A whole lot of other optimizations are being done during this build

Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149
1

UPDATE 2022:
Since version v12 ng build now produces production bundle by default. However historically --prod was an alias for --configuration=production. More details at https://angular.io/guide/build


TLTR;
--aot flag does not requited when you use --prod e.g ng build --prod


JIT compilation is the default when you run the ng build (build only) or ng serve (build and serve locally) CLI commands. For AOT compilation, include the --aot option with the ng build or ng serve commands:

ng build --aot
ng serve --aot

The ng build command with the --prod meta-flag (ng build --prod) compiles with AOT by default

You can customize your angular.json to include aot as default for a particular command, here is how you add aot for build:

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

AOT build and serve is recommended by angular team but not default yet. More details here

angularrocks.com
  • 26,767
  • 13
  • 87
  • 104
1

Default aot value depends on which angular version your are running:

Angular offers two ways to compile your application:

  • Just-in-Time (JIT), which compiles your app in the browser at runtime. This was the default until Angular 8.
  • Ahead-of-Time (AOT), which compiles your app and libraries at build time. This is the default since Angular 9.