12

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

kampsj
  • 3,139
  • 5
  • 34
  • 56

2 Answers2

3

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": {
      ...
    }
  }
}
Trevor Karjanis
  • 1,485
  • 14
  • 25
-3

Have you tried ng build --aot ?

https://angular.io/guide/aot-compiler

To test with production settings you could use ng test --environment=prod.

Neeraj Kumar
  • 771
  • 2
  • 16
  • 37
Eduard Ghinea
  • 87
  • 1
  • 8
  • 1
    Thing is that adding --environment=prod will not trigger what --prod flag triggers, especially minification (which is my main source of troubles). I truly wander how real prod builds can actually be tested. – Bob May 25 '18 at 16:48