Vikram
Vikram

Reputation: 3351

What does false do in aot build angular cli - Out of memory issue

What "false" do in ng build --prod --aot false command

I am working on an angular 4 app developed with ng cli, as it is a enterprise solution the app becomes so huge that it takes too much time to serve and build. I even got javascript out of memory issues and the I started using following command to build the app

ng build --prod --aot false

But I am not sure how it works

Upvotes: 4

Views: 14926

Answers (2)

yurzui
yurzui

Reputation: 214017

All available commands for angular-cli can be found here.

Now, when we run ng build --prod it means that we specify target for our application:

{
    name: 'target',
    type: String,
    default: 'development',
    aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }],
    description: 'Defines the build target.'
},

then angular-cli sets default options([email protected]) based on specified target:

// Fill in defaults for build targets
public addTargetDefaults(buildOptions: T): T {
  const targetDefaults: { [target: string]: Partial<BuildOptions> } = {
    development: {
      environment: 'dev',
      outputHashing: 'media',
      sourcemaps: true,
      extractCss: false,
      namedChunks: true,
      aot: false
    },
    production: {
      environment: 'prod',
      outputHashing: 'all',
      sourcemaps: false,
      extractCss: true,
      namedChunks: false,
      aot: true
    }
  };

that can also be found in docs

When you add --aot false you override default aot option. So it becomes false.

If you have some problem with aot building then there is some thread for that where the common solution is running build like:

package.json

"scripts": {
  "prod": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --prod" 
}

but besides above i prefer doing some refactoring code to reduce application size and help aot compiler to be executed faster.

Upvotes: 5

Fateh Mohamed
Fateh Mohamed

Reputation: 21367

AOT is by default true for production builds, if you want to deactivate is you can use:

ng build prod --no-aot 

or

ng build prod --aot=false

but using AOT will compile your templates to js before serving them, so the browser will load them very fast

Upvotes: 7

Related Questions