尝试获取angular-cli以识别angular.json
中的多个配置
C:\_dev\myapp>ng serve --configuration development
Configuration 'development' could not be found in project 'myapp'.
Error: Configuration 'development' could not be found in project 'myapp'.
片段是:
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.production.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
"development": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
],
"optimization": false,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": true,
"aot": false,
"extractLicenses": false,
"vendorChunk": true,
"buildOptimizer": false
}
}
src/environments/environment.development.ts
确实存在ng serve --configuration production
工作良好
最佳答案
angular.json文件的configurations
和build
部分中有一个serve
条目。服务部分还需要了解您的自定义配置。假设您的配置名称为 debug ,则将其添加到服务部分,如下所示
"projects": {
"myApp": {
[...]
"architect": {
"build": {
[...]
"configurations": {
"production": { [...] },
"debug": { [...] }
}
},
"serve": {
[...]
"configurations": {
"production": {
"browserTarget": "myApp:build:production"
},
"debug": {
"browserTarget": "myApp:build:debug"
}
}
}
}
}
}
不要忘记将
myApp
调整为您的项目名称,使其等于angular.json中project
部分的直接子代。同样,两个debug
都应与build
部分中的配置匹配。然后搭配
ng serve --configuration=debug
关于angular - Angular 6:多种配置(双重环境),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50477062/