angular - 如何添加/设置环境 Angular 6 angular.json 文件

标签 angular angular6

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

我如何/在此文件中的何处指定要使用的环境?

最佳答案

打开 angular.json 文件。我们可以看到默认情况下的配置,它将显示在生产环境中,为您各自的环境添加代码片段。在开发环境中添加 environment.dev.ts 文件,为 qa 添加 environment.qa.ts。根据您的喜好命名。 使用

 ng serve --configuration=environment_name

environment_name - (dev,qa,prod) ng 构建可以遵循相同的过程

"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 - 如何添加/设置环境 Angular 6 angular.json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50313296/

相关文章:

javascript - 多次订阅 Observable 与订阅一次并共享结果

angular - 使用路由在 Angular 6 中打开新的浏览器窗口

javascript - 如何将元素更改为 Angular 形式的输入或下拉列表?

css - ngBootstrap 捕获关于提前输入建议的点击事件

Angular6 将数据传递给 ng-template

angular6 - CKEditor 5 抛出无法读取 Angular6 项目中未定义的属性 'create'

单个 html 文件中的 Angular4

pdf - html2canvas 使用 angular2/typescript 使用 css 样式呈现文档 PDF

Angular TypeError : _angular_core__WEBPACK_IMPORTED_MODULE_1__. ɵɵdefineInjectable 不是函数

angular - 刷新 ListView 在运行时在 NativeScript 和 Angular 中添加新元素