Angular6以往版本自定义environment配置在.angular-cli.json文件中,
1、在.angular-cli.json文件中 “environments中"添加
例如:
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"simple": "environments/environment.simple.ts"
}
2、编译命令
ng build --base-href /saturn/ --prod --env=simple
Angular6.x版本后,.angular-cli.json文件演变成angular.json文件
如果需要加自定义配置文件environment.simple.ts
1、在angular.json文件中如下配置:
"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
},
"simple": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.simple.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
2、无任何配置,默认编译prod命令
ng build --base-href /myweb/ --prod --configuration=production
如需使用simple环境,则执行命令
ng build --base-href /myweb/ --prod --configuration=simple
网友评论