question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[webpack] Add ability to disable liveReload in webpackDevServer

See original GitHub issue

Preflight 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

https://github.com/electron-userland/electron-forge/blob/master/packages/plugin/webpack/src/WebpackPlugin.ts#L297

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yourfavoritecommented, Jun 6, 2021

@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 instead react-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)

image

1reaction
maleptcommented, Jun 6, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add ability to completely disable auto reload #758 - GitHub
Based on @jcrben's comment, I just tried updating webpack-dev-server from 2.4.5 to 2.5.0 (with webpack 2.6.1) and the problem does indeed appear ...
Read more >
How to disable webpack dev server auto reload?
The webpack client scripts are added by default to your bundle (since webpack 2), but you can disable those by adding --no-inline to...
Read more >
DevServer - webpack
Tell dev-server to enable/disable magic HTML routes (routes corresponding to your webpack output, for example /main for main.js ). webpack.config.js module.
Read more >
Option to disable webpack auto-refresh (livereload) - GitLab
Is there a way to disable this? I don't see inline mode set in our webpack.config.js but perhaps it defaults to true, https://webpack...
Read more >
webpack-dev-server - npm
Start using webpack-dev-server in your project by running `npm i ... --no-live-reload Disables live reloading on changing files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found