【问题标题】:Pass custom environment parameters to @angular-builders/custom-webpack将自定义环境参数传递给 @angular-builders/custom-webpack
【发布时间】:2020-05-25 08:52:14
【问题描述】:

在我们的 Angular 9 应用程序中,我们在 angular.json 中配置了多个环境。

我们还使用@angular-builders/custom-webpack 添加一些自定义插件,这些插件需要一些基于环境的输入变量,但是如果我向环境节点添加自定义属性,我会收到此错误:

数据路径“”不应该有额外的属性(customPluginConfigForSandboxEnvironment)

"architect": {
   "build": {
     "configurations": {
       "sandbox": {
        "outputPath": ....,
        "customPluginConfigForSandboxEnvironment": {}

有可能做这样的事情吗?

在 customWebpackConfig 文件中,我可以从选项中读取 outputPath

 module.exports = (config, options) => {

在这里保存我的额外配置,但如果可能的话,我更喜欢将所有配置保存到 angular.json 中。

谢谢

【问题讨论】:

  • 你有没有在 @angular-builders/custom-webpack webpack.config.js 文件中获得可用的环境变量?

标签: angular webpack angular-builder


【解决方案1】:

您可以使用两个单独的配置文件:

{
  ...
  "projects": {
    "your-app": {
      ...
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "mergeRules": {
                "externals": "replace"
              }
            },
            ...
          },
          "configurations": {
            "production": {
              "customWebpackConfig": {
                "path": "./webpack.config.prod.ts"
              },
              ...
            },
            "development": {
              "customWebpackConfig": {
                "path": "./webpack.config.dev.ts"
              }
            }
          },
          ...
        }
      }
    }
  }
}

【讨论】:

  • 是的,我们最终这样做了。感谢您的贡献!
猜你喜欢
  • 2019-07-08
  • 1970-01-01
  • 1970-01-01
  • 2017-07-30
  • 1970-01-01
  • 1970-01-01
  • 2011-09-17
  • 2018-03-09
  • 2021-10-26
相关资源
最近更新 更多