Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run angular cli ng test with production build settings and AOT enabled

Is there a way to run the angular cli tests with the command ng test that tells the underlining compiler to use the ng build --prod settings?

I ask because here are often aot compilation errors encountered with ng build --prod that do not occur with normal compilation with ng build

like image 375
kampsj Avatar asked Aug 11 '17 19:08

kampsj


People also ask

Does ng build prod use AOT?

The ng build command with the --prod meta-flag (ng build --prod) compiles with AOT by default. Why compile with AOT? With AOT, the browser downloads a pre-compiled version of the application. The browser loads executable code so it can render the application immediately, without waiting to compile the app first.

Does ng serve use AOT?

When you run the ng build (build only) or ng serve (build and serve locally) CLI commands, the type of compilation (JIT or AOT) depends on the value of the aot property in your build configuration specified in angular. json . By default, aot is set to true for new CLI applications.

How do you test a NG build?

To test your Angular build locally: Build your app: ng build --prod. Install http-server for serving the app: npm i -g http-server. cd (change directory) into the the build location and run the app with: http-server.


1 Answers

This is not possible, and I think that is because the test architect target is its own build configuration. Options like assets, scripts, and styles are supported, but options that are typically associated with production, like AOT, are not. This is because the compiler team considers the feature to be experimental. There is a feature request to support AOT.

To create a production configuration, add it to the test target.

"test": {
  "builder: "@angular-devkit/build-angular:karma",
  "options": {
    ...
  },
  "configurations": {
    "production": {
      ...
    }
  }
}
like image 130
Trevor Karjanis Avatar answered Sep 23 '22 07:09

Trevor Karjanis