使用多个配置构建应用程序

时间:2018-06-04 14:50:27

标签: angular angular-cli 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"
          ]
        }
      }
    },
  

▶预期行为:

我想添加/合并个别配置中指定的 styles 以及 {{1}中指定的 styles }} 即可。例如,使用以下命令:

build:options

上述命令应包含 ng build --configuration theme-one "src/styles.scss" "src/styles/themes/material.theme-one.scss"也是如此。

  

▶当前行为:

目前的行为是,当我指定配置时,会包含该配置中的 theme-two ,但会忽略 styles

知道如何实现这个目标吗?

1 个答案:

答案 0 :(得分:3)

在与Filipe Silva(来自CLI核心团队)讨论您的问题后,目前没有可用的API来执行此操作。我建议您在CLI repo上打开一个问题作为功能请求。

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

"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"
      ]
    }
  }

干杯。