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
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.
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.
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.
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": {
...
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With