[webpack] Add ability to disable liveReload in webpackDevServer
See original GitHub issuePreflight Checklist
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project follows, as appropriate.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
I am working on a React + Redux application using the Webpack + Typescript template and want to get Hot Module Replacement working for my React components. By default, whenever I update a module, the log will say Content base changed. Reloading...
and the entire app reloads which resets my Redux state.
Proposed Solution
I’d like the ability to pass in additional options here. Specifically liveReload: false
. After I hardcoded this option in the WebpackPlugin.ts file, I was able to have the desired functionality of an individual module updating without breaking my Redux store. However I am not sure if this breaks other important functionality as I am currently just testing in a sandbox project.
Alternatives Considered
In the past I’ve used react-hot-loader
but that was on Webpack 4 and I’m not sure if there will be issues with Webpack 5. Another possibility that I have not yet looked into would be React Fast Refresh which has a Webpack plugin, though I have yet to try that with electron-forge.
Additional Information
In my testing, this did prevent the Redux store from resetting. However it does not prevent state within a React component from resetting. Ideally preservation of React component state would also work though this is less important for my purposes.
Even if there are better solutions for electron-forge + webpack HMR + react + redux, it could still be beneficial to allow custom options (and overrides) to be passed to the webpackDevServer.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top GitHub Comments
@malept Unfortunately I wasn’t able to get either of the alternatives working on my end.
react-hot-loader
didn’t work and I found some conversations over there stating that the package was deprecated and insteadreact-refresh-webpack-plugin
should be used. So I attempted that but it seems there is an incompatibility with webpack-dev-server somewhere as it throws the error below. I also had to do a --force install due to electron-forge using some beta webpack stuff (IIRC I saw webpack-dev-server)I am generally reluctant to add more code to the Webpack plugin if I can help it, because it’s currently pretty complex (even after a lot of it got refactored for Webpack 5, which got rid of a lot of complexity), which makes it pretty difficult to maintain.