Webpack plugin to enable React Fast Refresh (Hot Reloading) for React components during development
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive configuration options for the ReactRefreshPlugin to customize Fast Refresh behavior and integration.
Creates a new instance of the React Refresh Plugin with optional configuration.
/**
* @param {ReactRefreshPluginOptions} [options] Options for react-refresh-plugin.
*/
constructor(options?: ReactRefreshPluginOptions);Usage Example:
const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const plugin = new ReactRefreshPlugin({
exclude: /node_modules/,
include: /\.[jt]sx?$/,
forceEnable: false,
overlay: {
sockIntegration: 'wds'
}
});Applies the plugin to a Webpack compiler instance.
/**
* Applies the plugin.
* @param {import('webpack').Compiler} compiler A webpack compiler object.
* @returns {void}
*/
apply(compiler: import('webpack').Compiler): void;Usage Example:
// Automatically called by Webpack when plugin is added to plugins array
module.exports = {
plugins: [
new ReactRefreshPlugin(options)
]
};Main configuration interface for customizing plugin behavior.
interface ReactRefreshPluginOptions {
/**
* Enables strict ES Modules compatible runtime.
*/
esModule?: boolean | ESModuleOptions;
/**
* Files to explicitly exclude from processing.
*/
exclude?: string | RegExp | (string | RegExp)[];
/**
* Enables the plugin forcefully.
*/
forceEnable?: boolean;
/**
* Files to explicitly include for processing.
*/
include?: string | RegExp | (string | RegExp)[];
/**
* Name of the library bundle.
*/
library?: string;
/**
* Modifies how the error overlay integration works in the plugin.
*/
overlay?: boolean | ErrorOverlayOptions;
}Enables the plugin forcefully, bypassing normal development mode checks.
forceEnable?: boolean;Usage Examples:
// Enable in production (not recommended)
new ReactRefreshPlugin({
forceEnable: true
});
// Enable with 'none' mode without NODE_ENV
new ReactRefreshPlugin({
forceEnable: process.env.WEBPACK_MODE !== 'production'
});Default: undefined
Use Cases:
none mode in Webpack without setting NODE_ENVelectron-prerenderControl which files are processed by the plugin using patterns similar to Webpack's module.rules.
exclude?: string | RegExp | (string | RegExp)[];
include?: string | RegExp | (string | RegExp)[];Usage Examples:
// Exclude node_modules and specific directories
new ReactRefreshPlugin({
exclude: [/node_modules/, /\.spec\.[jt]sx?$/]
});
// Include only specific file patterns
new ReactRefreshPlugin({
include: /src\/.*\.[jt]sx?$/
});
// Multiple patterns
new ReactRefreshPlugin({
exclude: [
/node_modules/,
/build/,
path.resolve(__dirname, 'vendor')
]
});Defaults:
exclude: /node_modules/include: /\.([jt]sx?|flow)$/iSets a namespace for the React Refresh runtime, useful when multiple instances run simultaneously.
library?: string;Usage Examples:
// Set custom library namespace
new ReactRefreshPlugin({
library: 'MyApp'
});
// Use webpack output configuration
module.exports = {
output: {
library: 'MyLibrary'
},
plugins: [
new ReactRefreshPlugin() // Will use 'MyLibrary'
]
};Default: '', or output.uniqueName in Webpack 5, or output.library if set
Controls ES Modules compatibility for the refresh runtime.
esModule?: boolean | ESModuleOptions;
interface ESModuleOptions {
/**
* Files to explicitly exclude from flagged as ES Modules.
*/
exclude?: string | RegExp | (string | RegExp)[];
/**
* Files to explicitly include for flagged as ES Modules.
*/
include?: string | RegExp | (string | RegExp)[];
}Usage Examples:
// Enable ES Modules globally
new ReactRefreshPlugin({
esModule: true
});
// Granular ES Module control
new ReactRefreshPlugin({
esModule: {
include: /src\/.*\.m[jt]s$/,
exclude: /legacy/
}
});
// Auto-detection (default)
new ReactRefreshPlugin({
esModule: undefined // Plugin will infer from package.json type or file extension
});Default: undefined (auto-detection based on package.json type field or file extensions .mjs/.cjs)
Internal interface representing processed plugin options after normalization.
interface NormalizedPluginOptions {
esModule?: boolean | ESModuleOptions;
exclude: string | RegExp | (string | RegExp)[];
include: string | RegExp | (string | RegExp)[];
forceEnable?: boolean;
library?: string;
overlay: false | NormalizedErrorOverlayOptions;
}The plugin uses JSON schema validation to ensure correct configuration.
Schema Location: lib/options.json
Validation Features:
Error Handling:
// Invalid configuration will throw during plugin instantiation
try {
new ReactRefreshPlugin({
invalidOption: true // Will throw validation error
});
} catch (error) {
console.error('Plugin configuration error:', error.message);
}Install with Tessl CLI
npx tessl i tessl/npm-pmmmwh--react-refresh-webpack-plugin