angular6 ------ build multiple environments

本文介绍如何在 Angular 6 中配置不同环境变量,包括设置开发、测试等环境,通过修改 angular.json 文件实现多环境部署。文章详细说明了如何创建不同的环境文件并为构建过程指定相应的配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值