4

这是angular.json的一部分:

"configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }

我要做的是控制开发环境。例如更改sourceMapfalse,我不想通过将参数添加到ng build. 是否有任何相当于productioninside angular.jsonwhich 将指代开发

还有一些非常重要的事情:在 Angular-CLI 6 中没有ng eject!那么,如何查看和修改webpack.config.js呢?

4

2 回答 2

6

所有环境的默认设置都在architect > build > options属性中配置

 "projects": {
    "MyProject": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",

            //Add settings here
            "sourceMap": false,
             "fileReplacements": [
                {
                    "replace": "src/environments/environment.ts",
                    "with": "src/environments/environment.anotherdevenv.ts"
                }
            ]

这些设置按原样用于开发环境,因此您可以修改它(但如果它们不覆盖指定的设置,这将影响其他环境)

您还可以创建自己的“开发”配置(例如,通过复制生产配置,并根据您的需要进行更改),并在该配置中指定特定于开发环境的设置。然后运行下面的命令

ng serve -c development

eject命令暂时禁用,但根据 Angular cli 团队核心成员的评论,应尽快将其添加回来(https://github.com/angular/angular-cli/issues/10945

于 2018-05-24T10:13:27.370 回答
0

我在这里找到了 webpack 配置:node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js

于 2018-08-08T10:00:36.883 回答