angular6 ------ build multiple environments

At the first place, before version 6, ng build --env=dev its ok.
but in angular6, –env is not supported . –env got changed into –configuration or -c ( and now is more powerful).
Before pack the project, we need to set multiple environments. In addition to add new file, its required to do some changes in angular.json file.
add new configuration in the build (.. “build”:{“configuration”:…. property })
new build configuration may contain only file Replacements part
add new configuration in the serve { … “serve”: “configurations”: … property
new serve configuration shall contain of browserTarget=”your-project-name:build:staging”

for example:
1. add environment.uat.ts
2. copy configuration property of build and paste in the build. change the configuration name and path into other name and path.
"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.uat.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}

finally , ng build -c=uat it works!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章