简体   繁体   中英

Pass custom environment parameters to @angular-builders/custom-webpack

in our Angular 9 application we have multiple environments configured in angular.json.

We also use @angular-builders/custom-webpack to add some custom plugins that need some input variables based on environment but if I add a custom property to the environment node i get this error:

Data path "" should NOT have additional properties(customPluginConfigForSandboxEnvironment)

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

Is it possible to do something like this?

In the customWebpackConfig file I can read the outputPath from options

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

and here save my extra configuration, but I prefer to keep all the configurations into the angular.json if it's possible.

Thanks

You can use two separate configuration files:

{
  ...
  "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"
              }
            }
          },
          ...
        }
      }
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM