electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.49k stars 517 forks source link

Webpack plugin: add escape hatch for custom webpack configs #3215

Open chromakode opened 1 year ago

chromakode commented 1 year ago

Pre-flight checklist

Problem description

In a similar vein to https://github.com/electron/forge/issues/3169, my project requires an additional webpack bundle to function: a target: web bundle served by a webserver. Currently this is very hard to accomplish with WebpackPlugin.

Proposed solution

It'd be really useful to add an "escape hatch" or two to enable custom webpack config. One option would be to add an extraConfig option:

plugins: [
    {
      name: '@electron-forge/plugin-webpack',
      config: {
        extraConfig: ['./webpack.extra.config.js'],
      }
    }
  ]

Another option would be to provide hooks for modifying the webpack config for the renderer or main process before they run. This would be the most flexible for projects with complex builds, though care would need to be taken by users when upgrading electron-forge since the webpack config generated isn't expected to be stable.

Alternatives considered

Eventually I ended up monkeypatching WebpackConfig.getRendererConfig to add my extra webpack config object. This gives me watch mode for free, which is handy.

Additional information

No response

HMaker commented 1 year ago

@chromakode can you share your workaround? I have the same issue, I need to build a bundle to target browsers.