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

Viewed 2829

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

2 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": {
      ...
    }
  }
}
Related