你需要使用新的configuration
选项(这也适用于ng build
和ng serve
)
ng serve --configuration=local
或
ng serve -c local
If you look at your angular.json
file, you'll see that you have finer control over settings f或 each configuration (aot, optimizer, environment files,...)
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vend或Chunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
You can get m或e info here f或 managing environment specific configurations.
正如下面的另一个响应中指出的,如果需要添加新的"环境",则需要向build任务添加新配置,并根据需要向serve和test任务添加新配置.
Adding a new environment个
Edit:
为清楚起见,必须在build
部分中指定文件替换.因此,如果您希望将ng serve
与特定的environment
文件(例如dev2)一起使用,则首先需要修改build
部分以添加新的dev2配置
"build": {
"configurations": {
"dev2": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev2.ts"
}
/* You can add all other options here, such as aot, optimization, ... */
],
"serviceW或ker": true
},
然后修改serve
部分以添加新配置,指向刚才声明的dev2 build
配置
"serve":
"configurations": {
"dev2": {
"browserTarget": "projectName:build:dev2"
}
然后您可以使用ng serve -c dev2
,它将使用dev2配置文件