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

Add HMR support to React via react-refresh

Open hailwood opened this issue 5 years ago • 5 comments

It was pretty simple to add so I'm adding this here both for documentation purposes, but also this is probably something really helpful to enable by default if you use Encore.enableReactPreset()...

npm install @pmmmwh/react-refresh-webpack-plugin react-refresh


if(Encore.isDevServer()) {
  const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
  Encore.addPlugin(new ReactRefreshWebpackPlugin());

  Encore.configureBabel(config => {
    config.plugins.push(require('react-refresh/babel'))
  });
}

hailwood avatar Oct 31 '20 08:10 hailwood

In my case, I had to disable liveReload from the dev-server options to work

ahmed-saber avatar Feb 15 '21 11:02 ahmed-saber

@ahmed-saber yep, see #931

hailwood avatar Feb 15 '21 20:02 hailwood

This works like a charm!

rrenteria-dev avatar Sep 22 '23 20:09 rrenteria-dev