在Angular 5中, 我们可以使用
为不同的环境生成构建ng build --prod --env=uat
迁移到Angular 6后,上面的命令会抛出错误
Unknown option: '--env'
答案 0 :(得分:2)
我已经在Angular 6项目中进行了测试。
ng build --prod --configuration=uat
似乎不起作用,因为它仅在运行此命令时选择uat配置,并且忽略--prod
标志并且不应用任何优化,例如aot,minification和upglification等。< / p>
运行ng build --prod --configuration=uat
的效果与仅运行ng build --configuration=uat
的效果相同。为了应用其他配置选项,我们需要在angular.json的uat构建选项中显式添加它们
"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
}
}
}
答案 1 :(得分:1)
您可以尝试使用:
ng build --configuration=uat
答案 2 :(得分:0)
Prod: ng build --prod
Qa: ng build --configuration=qa
angular.json
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
},
"qa": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.qa.ts"
}
]
}
PROD:
export const environment = {
production: true,
api : 'https://example.com'
}
QA:
export const environment = {
production: true,
api : 'https://example-Qa.com'
}
dev environment
export const environment = {
production:false,
api : 'https://example-dev.com'
}