Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { NormalizedPluginOptions, PluginOptions } from './options';
import { getIntegrationEntry } from './utils/getIntegrationEntry';

export type { PluginOptions };
export const loader = 'builtin:react-refresh-loader';

function addEntry(entry: string, compiler: Compiler) {
new compiler.webpack.EntryPlugin(compiler.context, entry, {
Expand Down Expand Up @@ -72,15 +73,17 @@ class ReactRefreshRspackPlugin {
$ReactRefreshRuntime$: reactRefreshPath,
}).apply(compiler);

compiler.options.module.rules.unshift({
// biome-ignore lint: exists
include: this.options.include!,
exclude: {
if (this.options.injectLoader) {
compiler.options.module.rules.unshift({
// biome-ignore lint: exists
or: [this.options.exclude!, [...runtimePaths]].filter(Boolean),
},
use: 'builtin:react-refresh-loader',
});
include: this.options.include!,
exclude: {
// biome-ignore lint: exists
or: [this.options.exclude!, [...runtimePaths]].filter(Boolean),
},
use: loader,
});
}

const definedModules: Record<string, string | boolean> = {
// For Multiple Instance Mode
Expand Down
7 changes: 7 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export type PluginOptions = {
* @default false
*/
overlay?: boolean | Partial<OverlayOptions>;

/**
* Whether to inject the builtin:react-refresh-loader
* @default true
*/
injectLoader?: boolean;
};

export interface NormalizedPluginOptions extends Required<PluginOptions> {
Expand Down Expand Up @@ -90,6 +96,7 @@ export function normalizeOptions(
d(options, 'include', /\.([cm]js|[jt]sx?|flow)$/i);
d(options, 'library');
d(options, 'forceEnable', false);
d(options, 'injectLoader', true);
options.overlay = normalizeOverlay(options.overlay);
return options as NormalizedPluginOptions;
}