angular - 构建具有多个配置的应用程序

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

Is it possible to combine common styles along with configuration specific styles? Or to be specific, build app with multiple configurations?


我有一个应用程序,它根据构建期间使用的配置使用不同的 Material 主题。这是应用的 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"
          ]
        }
      }
    },

▶ Expected Behavior:

我想添加/组合在个别配置中指定的样式以及在中指定的样式 构建:选项。例如,使用以下命令:

ng build --configuration theme-one

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

▶ Current Behavior:

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

知道如何实现吗?

最佳答案

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

干杯。

关于angular - 构建具有多个配置的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50683303/

相关文章:

angular - 我能够在 Angular 8 的输入字段中显示从 API 获取的数据,但在控制台中出现错误

javascript - Angular 在数组中定义的特定索引上运行 *ngFor

angular - 使用 Ng2 图表在堆叠条形图中显示标签

angular - 找不到名称 'HammerManager'

angular - 如何使用 Angular Material 创建折叠菜单?

angular - 如何在 Angular 6 中观察服务变量

node.js - 如何从node-express获取图像并在Angular 8中查看图像

angular - 找不到模块 portfinder - 最新的 Angular CLI

angular - 使用 Angular CLI 时转译的 js 文件在哪里

css - Angular 6中不同组件的相同样式类