如何添加/设置环境Angular 6 angular.json文件 [英] How to add/set environment Angular 6 angular.json file

查看:96
本文介绍了如何添加/设置环境Angular 6 angular.json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何指定在Angular 6中使用的环境? .angular-cli.json文件似乎已从以前的版本更改为angular.json,并且其中的json结构也是如此.

How to 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.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构建可以遵循相同的过程

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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆