Installations
npm install @umijs/react-refresh-webpack-plugin
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>= 10.13
Node Version
16.20.2
NPM Version
8.19.4
Score
58.8
Supply Chain
67.6
Quality
76.4
Maintenance
50
Vulnerability
95.1
License
Releases
Contributors
Languages
JavaScript (100%)
Developer
pmmmwh
Download Statistics
Total Downloads
1,162,206
Last Day
3,530
Last Week
37,520
Last Month
179,647
Last Year
973,345
GitHub Statistics
3,157 Stars
870 Commits
194 Forks
18 Watching
5 Branches
48 Contributors
Package Meta Information
Latest Version
0.5.11
Package Id
@umijs/react-refresh-webpack-plugin@0.5.11
Unpacked Size
127.86 kB
Size
35.24 kB
File Count
58
NPM Version
8.19.4
Node Version
16.20.2
Publised On
08 Sept 2023
Total Downloads
Cumulative downloads
Total Downloads
1,162,206
Last day
-46.5%
3,530
Compared to previous day
Last week
-17.7%
37,520
Compared to previous week
Last month
44.2%
179,647
Compared to previous month
Last year
415.4%
973,345
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
9
Peer Dependencies
8
Dev Dependencies
43
React Refresh Webpack Plugin
An EXPERIMENTAL Webpack plugin to enable "Fast Refresh" (also known as Hot Reloading) for React components.
This plugin is not 100% stable. We're hoping to land a v1 release soon - please help us by reporting any issues you've encountered!
Getting Started
Prerequisites
Ensure that you are using at least the minimum supported versions of this plugin's peer dependencies - older versions unfortunately do not contain code to orchestrate "Fast Refresh", and thus cannot be made compatible.
We recommend using the following versions:
Dependency | Version |
---|---|
react | 16.13.0 +, 17.x or 18.x |
react-dom | 16.13.0 +, 17.x or 18.x |
react-refresh | 0.10.0 + |
webpack | 4.46.0 + or 5.2.0 + |
Minimum requirements
Dependency | Version |
---|---|
react | 16.9.0 |
react-dom | 16.9.0 |
react-refresh | 0.10.0 |
webpack | 4.43.0 |
Using custom renderers (e.g. react-three-fiber
, react-pdf
, ink
)
To ensure full support of "Fast Refresh" with components rendered by custom renderers,
you should ensure the renderer you're using depends on a recent version of react-reconciler
.
We recommend version 0.25.0
or above, but any versions above 0.22.0
should work.
If the renderer is not compatible, please file them an issue instead.
Installation
With all prerequisites met, you can install this plugin using your package manager of choice:
1# if you prefer npm 2npm install -D @pmmmwh/react-refresh-webpack-plugin react-refresh 3 4# if you prefer yarn 5yarn add -D @pmmmwh/react-refresh-webpack-plugin react-refresh 6 7# if you prefer pnpm 8pnpm add -D @pmmmwh/react-refresh-webpack-plugin react-refresh
The react-refresh
package (from the React team) is a required peer dependency of this plugin.
We recommend using version 0.10.0
or above.
Support for TypeScript
TypeScript support is available out-of-the-box for those who use webpack.config.ts
.
Our exported types however depends on type-fest
, so you'll have to add it as a devDependency
:
1# if you prefer npm 2npm install -D type-fest 3 4# if you prefer yarn 5yarn add -D type-fest 6 7# if you prefer pnpm 8pnpm add -D type-fest
:memo: Note:
type-fest@2.x
only supports Node.js v12.20 or above. If you're using an older version of Node.js, please installtype-fest@1.x
.
Usage
For most setups, we recommend integrating with babel-loader
.
It covers the most use cases and is officially supported by the React team.
The example below will assume you're using webpack-dev-server
.
If you haven't done so, set up your development Webpack configuration for Hot Module Replacement (HMR).
1const isDevelopment = process.env.NODE_ENV !== 'production'; 2 3module.exports = { 4 mode: isDevelopment ? 'development' : 'production', 5 devServer: { 6 hot: true, 7 }, 8};
Using webpack-hot-middleware
1const webpack = require('webpack'); 2 3const isDevelopment = process.env.NODE_ENV !== 'production'; 4 5module.exports = { 6 mode: isDevelopment ? 'development' : 'production', 7 plugins: [isDevelopment && new webpack.HotModuleReplacementPlugin()].filter(Boolean), 8};
Using webpack-plugin-serve
1const { WebpackPluginServe } = require('webpack-plugin-serve'); 2 3const isDevelopment = process.env.NODE_ENV !== 'production'; 4 5module.exports = { 6 mode: isDevelopment ? 'development' : 'production', 7 plugins: [isDevelopment && new WebpackPluginServe()].filter(Boolean), 8};
Then, add the react-refresh/babel
plugin to your Babel configuration and this plugin to your Webpack configuration.
1const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); 2 3const isDevelopment = process.env.NODE_ENV !== 'production'; 4 5module.exports = { 6 mode: isDevelopment ? 'development' : 'production', 7 module: { 8 rules: [ 9 { 10 test: /\.[jt]sx?$/, 11 exclude: /node_modules/, 12 use: [ 13 { 14 loader: require.resolve('babel-loader'), 15 options: { 16 plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean), 17 }, 18 }, 19 ], 20 }, 21 ], 22 }, 23 plugins: [isDevelopment && new ReactRefreshWebpackPlugin()].filter(Boolean), 24};
:memo: Note:
Ensure both the Babel transform (
react-refresh/babel
) and this plugin are enabled only indevelopment
mode!
Using ts-loader
:warning: Warning: This is an un-official integration maintained by the community.
Install react-refresh-typescript
.
Ensure your TypeScript version is at least 4.0.
1# if you prefer npm 2npm install -D react-refresh-typescript 3 4# if you prefer yarn 5yarn add -D react-refresh-typescript 6 7# if you prefer pnpm 8pnpm add -D react-refresh-typescript
Then, instead of wiring up react-refresh/babel
via babel-loader
,
you can wire-up react-refresh-typescript
with ts-loader
:
1const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); 2const ReactRefreshTypeScript = require('react-refresh-typescript'); 3 4const isDevelopment = process.env.NODE_ENV !== 'production'; 5 6module.exports = { 7 mode: isDevelopment ? 'development' : 'production', 8 module: { 9 rules: [ 10 { 11 test: /\.[jt]sx?$/, 12 exclude: /node_modules/, 13 use: [ 14 { 15 loader: require.resolve('ts-loader'), 16 options: { 17 getCustomTransformers: () => ({ 18 before: [isDevelopment && ReactRefreshTypeScript()].filter(Boolean), 19 }), 20 transpileOnly: isDevelopment, 21 }, 22 }, 23 ], 24 }, 25 ], 26 }, 27 plugins: [isDevelopment && new ReactRefreshWebpackPlugin()].filter(Boolean), 28};
ts-loader
won't work with HMR unlesstranspileOnly
is set totrue
. You should useForkTsCheckerWebpackPlugin
if you need typechecking during development.
Using swc-loader
:warning: Warning: This is an un-official integration maintained by the community.
Ensure your @swc/core
version is at least 1.2.86
.
It is also recommended to use swc-loader
version 0.1.13
or above.
Then, instead of wiring up react-refresh/babel
via babel-loader
,
you can wire-up swc-loader
and use the refresh
transform:
1const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); 2 3const isDevelopment = process.env.NODE_ENV !== 'production'; 4 5module.exports = { 6 mode: isDevelopment ? 'development' : 'production', 7 module: { 8 rules: [ 9 { 10 test: /\.[jt]sx?$/, 11 exclude: /node_modules/, 12 use: [ 13 { 14 loader: require.resolve('swc-loader'), 15 options: { 16 jsc: { 17 transform: { 18 react: { 19 development: isDevelopment, 20 refresh: isDevelopment, 21 }, 22 }, 23 }, 24 }, 25 }, 26 ], 27 }, 28 ], 29 }, 30 plugins: [isDevelopment && new ReactRefreshWebpackPlugin()].filter(Boolean), 31};
Starting from version
0.1.13
,swc-loader
will set thedevelopment
option based on Webpack'smode
option.swc
won't enable fast refresh whendevelopment
isfalse
.
For more information on how to set up "Fast Refresh" with different integrations, please check out our examples.
Overlay Integration
This plugin integrates with the most common Webpack HMR solutions to surface errors during development - in the form of an error overlay.
By default, webpack-dev-server
is used,
but you can set the overlay.sockIntegration
option to match what you're using.
The supported versions are as follows:
Dependency | Version |
---|---|
webpack-dev-server | 3.6.0 + or 4.x |
webpack-hot-middleware | 2.x |
webpack-plugin-serve | 0.x or 1.x |
API
Please refer to the API docs for all available options.
FAQs and Troubleshooting
Please refer to the Troubleshooting guide for FAQs and resolutions to common issues.
License
This project is licensed under the terms of the MIT License.
Special Thanks
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7
Reason
Found 0/1 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 29 are checked with a SAST tool
Reason
23 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5
- Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp
- Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq
- Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr
- Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765
- Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
Score
3
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More