在 Angular 5 中,我们可以使用
ng build --prod --env=uat
迁移到 Angular 6 后,上述命令会引发错误
Unknown option: '--env'
在 Angular 5 中,我们可以使用
ng build --prod --env=uat
迁移到 Angular 6 后,上述命令会引发错误
Unknown option: '--env'
我已经在 Angular 6 项目中进行了测试。
ng build --prod --configuration=uat
似乎不起作用,因为它仅在您运行此命令时选择 uat 配置并忽略--prod
标志并且不应用任何优化,例如 aot、缩小和升级等。
跑步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
}
}
}
你可以尝试使用:
ng build --configuration=uat
你可以尝试使用
ng build ---产品
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'
}