electron-webpack
electron-webpack copied to clipboard
Hot reload question
Hi! When I change main file of the electron app it rebuilds successfully but the app continues using the old file. What I'm missing?
My webpack config `const path = require('path');
module.exports = { entry: './electron/main.ts', devtool: 'inline-source-map', target: 'electron-main', node: { __dirname: false }, output: { filename: 'main.js', publicPath: path.join(__dirname, 'dist', 'main'), path: path.join(__dirname, 'dist', 'main'), }, resolve: { extensions: [ '.tsx', '.ts', '.js' ] }, module: { rules: [ { test: /.tsx?$/, use: 'ts-loader', exclude: /node_modules/, }, { test: /.m?js$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } } ] }, devServer: { contentBase: path.join(__dirname, 'dist'), publicPath: path.join(__dirname, 'dist', 'main'), compress: true, port: 9000 } }; `
@IhorVimmi are you using if (module.hot) hot.accept()
in the main file?
@loopmode yes i do http://joxi.ru/zANdjKJhvgwWom
When invoked without any arguments, as in the snippet you posted, all and any changes are accepted as hot and the process is not restarted. For module dependencies ("children" of the main file), this is desired, but not for the main file itself. I don't know how to exactly do this, but I believe one must not accept changes to the main file itself for HMR. Or otherwise, maybe there can be a setup with an additional module and clever placement of the hot.accept() somewhere further down the dependency tree (not in the entry file itself). Or maybe even a webpack config tweak. But I think effectively, if there are changes in the entry file for the main process itself, HMR can't work and the process must be restarted.
I've got the same error. If the entry
field is set, when the code is changed, the webpack bundle is recreated but the app does not restart.
When I remove the entry
field form the webpack configs, everything works fine.