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 this plugin and react-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. Add the plugin in your webpack.config.js
The webpack loader is registered internally
const ReactRefreshPlugin = require('@webhotelier/webpack-fast-refresh');
config.plugins.unshift(new ReactRefreshPlugin());3. Add React's plugin in your babel config
{
"plugins": ["react-refresh/babel"]
}4. Launch the server
Make sure you have HMR enabled.
Using webpack-dev-server:
webpack-dev-server --hot --mode developmentIn webpack.config.js:
config.entry.main.unshift(require.resolve('webpack-hot-middleware/client'));
config.plugins.push(new webpack.HotModuleReplacementPlugin());In your express init file:
if (app.get('env') === 'development') {
const webpack = require('webpack');
const webpackConfig = require('../webpack.config');
const webpackCompiler = webpack(webpackConfig);
app.use(
require('webpack-dev-middleware')(webpackCompiler, {
lazy: false,
logLevel: 'error', // trace, debug, info, warn, error, silent
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,
})
);
}