问题描述
如何指定要在 Angular 6+ 中使用的环境?.angular-cli.json
文件似乎已从以前的版本更改为 angular.json
并且其中包含 json
的结构.
How do I specify the environment to use in Angular 6+? The .angular-cli.json
file seems to have changed to angular.json
from previous versions and with it the structure of the json
within.
我如何/在此文件中指定要使用的环境?
How/where in this file do I specify the environments to use?
推荐答案
打开 angular.json 文件.我们可以看到默认情况下的配置,它将显示为您各自环境的生产添加代码片段.在environment中为dev添加environment.dev.ts文件,为qa添加environment.qa.ts.根据您的喜好命名.使用
Open angular.json file. we can see the configurations by default it will be shown for production add code snippet for your respective environments. add environment.dev.ts file in environment for dev, add environment.qa.ts for qa. Name as you prefered.use
ng serve --configuration=environment_name
environment_name - (dev,qa,prod) ng build 可以遵循相同的过程
environment_name - (dev,qa,prod) same process can be followed for ng build
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
"dev": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
"qa": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.qa.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
这篇关于如何添加/设置环境 Angular 6 angular.json 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!