Skip to content

Commit

Permalink
feat: handle react-refresh resolving in `@rspack/plugin-react-refre…
Browse files Browse the repository at this point in the history
…sh` (#4267)
  • Loading branch information
h-a-n-a authored Oct 8, 2023
1 parent 96acdcc commit 9bd940c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/rspack-plugin-react-refresh/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
};
}
};

Expand Down
2 changes: 2 additions & 0 deletions packages/rspack/src/web/ResolveSwcPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 9bd940c

Please sign in to comment.