jen*_*ent 31 angular-cli angular angular6
试图让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'.
Run Code Online (Sandbox Code Playgroud)
该片段是:
"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
}
}
Run Code Online (Sandbox Code Playgroud)
src/environments/environment.development.ts 确实存在
ng serve --configuration production
Run Code Online (Sandbox Code Playgroud)
工作良好
ngf*_*ixl 54
angular.json文件的部分和configurations条目中有一个条目.服务部分也需要了解您的自定义配置.假设您的配置名称是debug,请将其添加到serve部分,如下所示buildserve
"projects": {
"myApp": {
[...]
"architect": {
"build": {
[...]
"configurations": {
"production": { [...] },
"debug": { [...] }
}
},
"serve": {
[...]
"configurations": {
"production": {
"browserTarget": "myApp:build:production"
},
"debug": {
"browserTarget": "myApp:build:debug"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
不要忘记调整myApp您的项目名称等于angular.json中该project部分的直接子项.两者都debug应该符合您在配置中的配置build.
然后服务
ng serve --configuration=debug
Run Code Online (Sandbox Code Playgroud)