Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify environment via `ng build` in Angular 6 app

Tags:

In Angular 5, we could generate build for different environments using

ng build --prod --env=uat 

After migration to Angular 6 the above command throws error

Unknown option: '--env' 
like image 416
Nehal Damania Avatar asked May 10 '18 05:05

Nehal Damania


People also ask

How do you find the Angular environment?

If you want to know the mode of Angular, as @yurzui said, you need to call { isDevMode } from @angular/core but it can return false only if you call enableProdMode before it.


2 Answers

One needs to use the configuration option

ng build --prod --configuration=uat 

or

ng build --prod -c uat 

More information here

Also for ng serve same option as answered here

like image 169
Nehal Damania Avatar answered Sep 28 '22 22:09

Nehal Damania


I have tested in an Angular 6 Project.

ng build --prod --configuration=uat doesn't seem to work as it only picks uat configuration when you run this command and ignores --prod flag and doesn't apply any optimization such as aot, minification and upglification etc.

Running ng build --prod --configuration=uat has the effect as same as only running ng build --configuration=uat. In order to apply any other configuration options we need to add them explicitly in the uat build options in angular.json

"configurations": {         "production": {           "fileReplacements": [             {               "replace": "src/environments/environment.ts",               "with": "src/environments/environment.prod.ts"             }           ],           "optimization": true,           "outputHashing": "all",           "sourceMap": false,           "extractCss": true,           "namedChunks": false,           "aot": true,           "extractLicenses": true,           "vendorChunk": false,           "buildOptimizer": true         },         "uat": {           "fileReplacements": [             {               "replace": "src/environments/environment.ts",               "with": "src/environments/environment.test.ts"             }           ],           "optimization": true,           "outputHashing": "all",           "sourceMap": false,           "extractCss": true,           "namedChunks": false,           "aot": true,           "extractLicenses": true,           "vendorChunk": false,           "buildOptimizer": true         }       }     } 
like image 39
bhaskerchari Avatar answered Sep 28 '22 21:09

bhaskerchari