1.在environment文件夹下新建一个environment.test.ts文件
export const environment = {
production:true,
baseURL:'http://localhost:3002'
}
2.在angula.json文件夹中复制production字段的内容并改变
"test": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
//与production中为"with": "src/environments/environment.prod.ts"
"with": "src/environments/environment.test.ts"
}
],
"outputHashing": "all"
},
在serve字段下复制production字段的内容并更改
"test": {
"browserTarget": "test4:build:test"
// ng serve --configuration=test --port 4600
},
3.启动命令
ng serve --configuration=test --port 4600
//在4600端口下进行查看,可以看到test环境的环境变量已经改变,如下图