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

1
  • Any clue on that? I think that's a very important point.
    – Bob
    May 25, 2018 at 16:48

2 Answers 2

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": {
      ...
    }
  }
}
1
  • Does anyone has any up-to-date info on this experimental feature? Maybe @Trevor Karjanis? Thanks!
    – ddsultan
    Feb 16 at 7:17
-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.

1
  • 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, 2018 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.