Package Exports
- @webhotelier/webpack-fast-refresh
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@webhotelier/webpack-fast-refresh) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
webpack-fast-refresh
React Fast Refresh plugin and loader for webpack@5+
Usage
1. Install both react-refresh and webpack-fast-refresh in your project
yarn add -D -E @webhotelier/webpack-fast-refresh react-refresh
# or
npm install -D -E @webhotelier/webpack-fast-refresh react-refresh2. Configure webpack
Register the plugin in webpack.config.js:
const ReactRefreshPlugin = require('@webhotelier/webpack-fast-refresh');
config.plugins.unshift(new ReactRefreshPlugin());3. Configure babel
{
"plugins": ["react-refresh/babel"]
}4. Launch the server
Make sure you have HMR enabled.
Using webpack-dev-server:
webpack-dev-server --hot --mode developmentUsing webpack-hot-middleware:
In webpack.config.js:
config.entry.main.unshift(require.resolve('webpack-hot-middleware/client'));
config.plugins.push(new webpack.HotModuleReplacementPlugin());In your node server:
if (app.get('env') === 'development') {
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.json');
const webpackCompiler = webpack(webpackConfig);
app.use(
require('webpack-dev-middleware')(webpackCompiler, {
lazy: false,
publicPath: webpackConfig.output.publicPath,
headers: { 'Access-Control-Allow-Origin': '*' },
})
);
app.use(
require('webpack-hot-middleware')(webpackCompiler, {
path: '/__webpack_hmr',
heartbeat: 10 * 1000,
noInfo: false,
quiet: false,
})
);
}