diff --git a/packages/rspack-plugin-react-refresh/src/index.js b/packages/rspack-plugin-react-refresh/src/index.js index 567436fee99..cb75cefb28b 100644 --- a/packages/rspack-plugin-react-refresh/src/index.js +++ b/packages/rspack-plugin-react-refresh/src/index.js @@ -44,6 +44,10 @@ module.exports = class ReactRefreshRspackPlugin { */ this.options = normalizeOptions(options); } + + /** + * @param {import("@rspack/core").Compiler} compiler + */ apply(compiler) { new compiler.webpack.EntryPlugin(compiler.context, reactRefreshEntryPath, { name: undefined @@ -59,6 +63,12 @@ module.exports = class ReactRefreshRspackPlugin { }, use: "builtin:react-refresh-loader" }); + + const refreshPath = path.dirname(require.resolve("react-refresh")); + compiler.options.resolve.alias = { + "react-refresh": refreshPath, + ...compiler.options.resolve.alias + }; } }; diff --git a/packages/rspack/src/web/ResolveSwcPlugin.ts b/packages/rspack/src/web/ResolveSwcPlugin.ts index 10ac443338f..919f0621676 100644 --- a/packages/rspack/src/web/ResolveSwcPlugin.ts +++ b/packages/rspack/src/web/ResolveSwcPlugin.ts @@ -13,6 +13,8 @@ export class ResolveSwcPlugin { // redirect @swc/helpers to rspack, so user don't have to manual install it compiler.options.resolve.alias = { "@swc/helpers": swcPath, + // TODO: DEPRECATED: remove in v0.5.0. + // it's moved to `@rspack/plugin-react-refresh`, but it still required for `builtins.react` for now. "react-refresh": refreshPath, ...compiler.options.resolve.alias };