Angular 6:多种配置(twas 环境) [英] Angular 6: Multiple configurations (twas environments)
问题描述
尝试让 angular-cli 识别 angular.json
Trying to get angular-cli to recognise multiple configurations in 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
工作正常
推荐答案
build
和 serve
中有一个 configurations
条目angular.json 文件的一部分.服务部分也需要了解您的自定义配置.假设您的配置名称是 debug,请将其添加到 serve 部分,如下所示
There is a configurations
entry in the build
and in the serve
section of the angular.json file. The serve part needs to know about your custom configuration as well. Assuming your configuration name is debug, add it to the serve section as follows
"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
部分中的配置相匹配.
Don't forget to adjust myApp
to your projects name equal to the direct child of the project
section in your angular.json. Also both debug
's should match your configuration in build
section.
然后服务
ng serve --configuration=debug
这篇关于Angular 6:多种配置(twas 环境)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!