【发布时间】:2018-10-20 07:52:21
【问题描述】:
在 Angular 5 中, 我们可以使用
为不同的环境生成构建ng build --prod --env=uat
迁移到 Angular 6 后,上述命令抛出错误
Unknown option: '--env'
【问题讨论】:
标签: angular angular-cli angular6
在 Angular 5 中, 我们可以使用
为不同的环境生成构建ng build --prod --env=uat
迁移到 Angular 6 后,上述命令抛出错误
Unknown option: '--env'
【问题讨论】:
标签: angular angular-cli angular6
【讨论】:
ng build --help 中删除该信息。感谢@nehal 的分析器
ng build --prod --aot
--prod 和 --configuration。 --configuration 覆盖 --prod。 Source
ng build --prod --configuration=uat 正是我想要的。非常感谢!
你可以尝试使用
ng build ---prod
【讨论】:
我已经在 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
【讨论】:
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'
}
【讨论】: