I have an electron app that I'm building with Webpack 2. I have a custom module (mymodule
) that I want to be a separate bundle referenced by the other bundles. The problem is that when I use the CommonsChunkPlugin
with my main process, electron locks up as the app is starting. I can see the electron logo appear in the doc but the window never shows up.
Note that it doesn't have to be a module I wrote, I can use lodash
with CommonsChunkPlugin
and get the same result.
Interestingly, if I use the CommonsChunksPlugin
with the renderer process in the same way, everything works fine.
I put together a simple electron app that shows this issue.
The github repo gives more details on the situation, but here are the important parts:
electron main process:
const mymod = require('./mymodule')
app.on('ready', function() {
console.log(mymod.abc);
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadURL(url.format({
pathname: require('./index.html')
}));
});
webpack config for main:
entry: {
main: path.join(__dirname, './main.js'),
mymod: ['./mymodule']
},
output: {
path: __dirname + '/build/',
publicPath: __dirname + '/build/',
filename: '[name].bundle.js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('mymod')
]
In this state, the app will not work. If you then go into the webpack.main.js
file and comment out the use of the CommonsChunkPlugin
in these lines it will start working:
entry: {
main: path.join(__dirname, './main.js'),
// mymod: ['./mymodule']
},
output: {
path: __dirname + '/build/',
publicPath: __dirname + '/build/',
filename: '[name].bundle.js'
},
plugins: [
// new webpack.optimize.CommonsChunkPlugin('mymod')
]
Here is my environment info:
MacOS: 10.12.6
node: v6.11.0
npm: 3.10.10
electron: v1.6.12
wepback2: 3.5.5
So what's going on here? Is this a bug with electron, webpack, or my code?