'How do i create a custom ng build --qa Angular 5.2
I would like to create ng build --qa where it picks up environment.qa.ts and does AOT, bundling and Dead code elimination but not Minification and Uglification
How would I do this in Angular 5.2
Solution 1:[1]
In angular6 we are doing it like below:
Create your own environment.qa.ts file inside environments folder. Where you can edit the details or you can add some more details like URL for your qa environment:
export const environment = { production: false, URL:'http://something:8200' }Now in angular.json you will have to add the qa configuration inside configurations and also you need to mention file replacement over there.
"configurations": {
"qa": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.qa.ts" } ], "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true } }It's up to you, if you want buildOptimizer, optimizationand all to be done in qa build you can use these value to be true or you can remove these options.
3.Finally run your build with this command ng build --configuration=qa
Solution 2:[2]
For angular 5 version you just need to have the environment files created, e.g:
/src/environments/environment.prod.ts
environment.qa.ts
environment.ts
Then in angular.cli.json:
{
...
app [
{
...
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"qa": "environments/environment.qa.ts"
}
And from the console you just have to execute the following command:
ng build --env=qa
You can do a test and see that the values taken in that case are the ones from the environment.qa.ts
Solution 3:[3]
If you are doing angular6, you need to add your environment.qa.ts to your angular.json configurations.
After doing so in both the build and configuration section, simply run ng build --configuration=qa
Solution 4:[4]
Create your environment.qa.ts inside environments folder.

Then go to angular.json file and Under configurations options add the configuration for QA as
"qa": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.qa.ts"
}
]
},
And then go to package.json and add the script section as below
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod --aot --build-optimizer",
"build:prod": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --c prod --build-optimizer --aot",
"build:qa": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --c qa --build-optimizer --aot",
"build:dev": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --c dev --build-optimizer --aot",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
then you can run npm run build:qa for qa, and npm run build:dev for dev and npm run build:prod for prod
Solution 5:[5]
My solution is simple:
I create another file in environments folder 
Then go to angular.json file and Under configurations options add the configuration for QA as
And from the console I execute the following command: ng build --configuration qa
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DirtyMind |
| Solution 2 | joc7188 |
| Solution 3 | Mike Tung |
| Solution 4 | Jino Shaji |
| Solution 5 | Grafritz Design |

