Skip to content

Commit

Permalink
fix: use module.rules.include to avoid runtime inject it self (#4134)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored Sep 6, 2023
1 parent d877cc4 commit 0f61d3e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/rspack-dev-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"exports": {
"./react-refresh": "./src/reactRefresh.js",
"./react-refresh-entry": "./src/reactRefreshEntry.js",
"./runtime-path-regexp": "./src/runtimePathRegexp.js"
"./runtime-paths": "./src/runtimePaths.js"
}
}
17 changes: 0 additions & 17 deletions packages/rspack-dev-client/src/runtimePathRegexp.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/rspack-dev-client/src/runtimePaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require('path')
const reactRefreshPath = require.resolve('./reactRefresh.js')
const RefreshUtilsPath = require.resolve(
'@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils',
{
paths: [reactRefreshPath]
}
)
const RefreshRuntimeDirPath = path.dirname(
require.resolve('react-refresh', {
paths: [reactRefreshPath]
})
)

exports.runtimePaths = [
reactRefreshPath,
RefreshUtilsPath,
RefreshRuntimeDirPath
]
5 changes: 3 additions & 2 deletions packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import WebpackDevServer from "webpack-dev-server";
import type { ResolvedDevServer, DevServer } from "./config";
import { getRspackMemoryAssets } from "./middleware";
// @ts-expect-error
import { runtimePathRegexp } from "@rspack/dev-client/runtime-path-regexp";
import { runtimePaths } from "@rspack/dev-client/runtime-paths";

export class RspackDevServer extends WebpackDevServer {
/**
Expand Down Expand Up @@ -352,8 +352,9 @@ export class RspackDevServer extends WebpackDevServer {
this.addAdditionalEntries(compiler);

if (this.options.hot) {
console.log(runtimePaths);
compiler.options.module.rules.push({
test: runtimePathRegexp,
include: runtimePaths,
type: "js"
});
}
Expand Down

0 comments on commit 0f61d3e

Please sign in to comment.