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

Hot reload question

Open ihor-zinchenko opened this issue 5 years ago • 4 comments

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

ihor-zinchenko avatar Dec 12 '19 10:12 ihor-zinchenko

@IhorVimmi are you using if (module.hot) hot.accept() in the main file?

loopmode avatar Dec 22 '19 16:12 loopmode

@loopmode yes i do http://joxi.ru/zANdjKJhvgwWom

ihor-zinchenko avatar Dec 23 '19 10:12 ihor-zinchenko

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.

loopmode avatar Dec 23 '19 12:12 loopmode

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.

image

When I remove the entry field form the webpack configs, everything works fine.

radubuciuceanu avatar Sep 15 '21 16:09 radubuciuceanu