使用多种配置构建应用

Fai*_*sal 5 angular-cli angular angular6 angular-cli-v6

是否可以将常见样式与配置特定样式结合在一起?还是要具体说明一下,使用多种配置构建应用?


我有一个应用程序,它根据构建期间使用的配置使用不同的材质主题。这是build应用程序部分的angular.json外观:

"build": {
  "builder": "@angular-devkit/build-angular:browser",
    "options": {
        "outputPath": "dist/my-app",
        "index": "src/index.html",
        "main": "src/main.ts",
        "tsConfig": "src/tsconfig.app.json",
        "scripts": [ ],
        "styles": [
          // These are the common styles
          "src/styles.scss"
        ],
        "assets": [
          "src/assets",
          "src/favicon.ico"
        ]
      },
      "configurations": {
        "theme-one": {
          "styles": [                
            "src/styles/themes/material.theme-one.scss"
          ]
        },
        "theme-two": {
          "styles": [                
            "src/styles/themes/material.theme-two.scss"
          ]
        }
      }
    },
Run Code Online (Sandbox Code Playgroud)

?预期行为:

我想添加/合并styles各个配置中styles指定的以及中的指定build:options。例如,使用以下命令:

ng build --configuration theme-one
Run Code Online (Sandbox Code Playgroud)

上面的命令应包含"src/styles.scss""src/styles/themes/material.theme-one.scss"。相同theme-two

?当前行为:

当前行为是,当我指定配置时,该配置中的stylesfrom被包括在内,但build:options:styles被忽略。

知道我该如何实现吗?

Was*_*ham 3

在与 Filipe Silva(来自 CLI 核心团队)讨论您的问题后,目前没有可用的 API 来执行此操作。我建议您在 CLI 存储库上将此问题作为功能请求提出。

同时,实现此目的的一种方法是复制配置选项,如下所示:

"configurations": {
    "theme-one": {
      "styles": [   
        "src/styles.scss",          
        "src/styles/themes/material.theme-one.scss"
      ]
    },
    "theme-two": {
      "styles": [
        "src/styles.scss",                
        "src/styles/themes/material.theme-two.scss"
      ]
    }
  }
Run Code Online (Sandbox Code Playgroud)

干杯。