electron-webpack icon indicating copy to clipboard operation
electron-webpack copied to clipboard

Disable minification (which is breaking code sometimes)

Open aadiene opened this issue 5 years ago • 1 comments

  • Version: electron-webpack 2.8.2
  • Target: MacOS 10.15.4

I am trying to inject a preload script with a require exposition so I can use Spectron with it as recommended here

if (process.env.NODE_ENV === 'test') {
  window.electronRequire = require
}

But when running electron-webpack, minification change the function name and the require exposition does not work anymore.

...
"test" === process.env.NODE_ENV
        ? ((window.electronRequire = t(6))
...

Could you please give us a way to disable minification ?

aadiene avatar Apr 19 '20 23:04 aadiene

@aadiene you can create a custom.webpack.additions.js for renderer.webpackConfig to modify minimizer option

module.exports = (config) => {
    if (config.mode === 'production') {
        config.optimization.minimizer = [new TerserPlugin({
            // ... your config
            terserOptions: {
                mangle: false
            }
        })];
    }
    console.log(JSON.stringify(config, null, 2)); // to check if you have right set of configs
    return config;
};

alfrededison avatar Apr 27 '20 11:04 alfrededison