Gathering detailed insights and metrics for @pmmmwh/react-refresh-webpack-plugin
An interesting fact about npm is that it started as a weekend project by its creator, Isaac Z. Schlueter, in 2009. It was officially launched in January 2010.
Gathering detailed insights and metrics for @pmmmwh/react-refresh-webpack-plugin
An interesting fact about npm is that it started as a weekend project by its creator, Isaac Z. Schlueter, in 2009. It was officially launched in January 2010.
npm install @pmmmwh/react-refresh-webpack-plugin
58.8
Supply Chain
67.6
Quality
74.4
Maintenance
50
Vulnerability
94.6
License
3,148 Stars
869 Commits
194 Forks
18 Watching
5 Branches
48 Contributors
Updated on 20 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
14%
1,285,173
Compared to previous day
Last week
4.1%
6,681,145
Compared to previous week
Last month
1.4%
28,545,332
Compared to previous month
Last year
-5.8%
337,616,231
Compared to previous year
8
44
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!
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 + |
Dependency | Version |
---|---|
react | 16.9.0 |
react-dom | 16.9.0 |
react-refresh | 0.10.0 |
webpack | 4.43.0 |
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.
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.
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@4.x
only supports Node.js v16 or above,type-fest@3.x
only supports Node.js v14.16 or above, andtype-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
.
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};
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};
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!
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};
It is recommended to run
ts-loader
withtranspileOnly
is set totrue
. You can useForkTsCheckerWebpackPlugin
as an alternative if you need typechecking during development.
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.
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 or 5.x |
webpack-hot-middleware | 2.x |
webpack-plugin-serve | 0.x or 1.x |
Please refer to the API docs for all available options.
Please refer to the Troubleshooting guide for FAQs and resolutions to common issues.
This project is licensed under the terms of the MIT License.
No vulnerabilities found.
Reason
14 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
21 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-11
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