【问题标题】:Build App with Multiple Configurations使用多种配置构建应用程序
【发布时间】:2018-11-13 22:47:33
【问题描述】:

是否可以将常见样式与配置特定样式结合起来?或者具体来说,构建具有多个配置的应用?


我有一个应用程序,它根据构建期间使用的配置使用不同的材料主题。这是应用程序 angular.jsonbuild 部分的样子:

"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 以及 build:options 中指定的 styles .例如,使用以下命令:

ng build --configuration theme-one

上述命令应包括"src/styles.scss""src/styles/themes/material.theme-one.scss"theme-two 也一样。

▶ 当前行为:

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

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

【问题讨论】:

    标签: angular angular-cli angular6 angular-cli-v6


    【解决方案1】:

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

    干杯。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    • 2022-12-17
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    相关资源
    最近更新 更多