electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
905 stars 171 forks source link

Disable minification (which is breaking code sometimes) #362

Open aadiene opened 4 years ago

aadiene commented 4 years ago

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 ?

alfrededison commented 4 years ago

@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;
};