Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@biomejs/biome": "^1.8.3",
"@jest/reporters": "29.7.0",
"@jest/test-sequencer": "^29.7.0",
"@rspack/core": "npm:@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256",
"@rspack/core": "1.6.4",
"@rspack/plugin-react-refresh": "1.0.0",
"@types/express": "4.17.21",
"@types/jest": "29.5.12",
Expand Down
179 changes: 89 additions & 90 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
import type { Server } from "node:http";
import type { Socket } from "node:net";
import { type Compiler, MultiCompiler } from "@rspack/core";
import { type Compiler, DefinePlugin, MultiCompiler } from "@rspack/core";
import type { FSWatcher } from "chokidar";
import WebpackDevServer from "webpack-dev-server";
// @ts-ignore 'package.json' is not under 'rootDir'
Expand Down Expand Up @@ -79,6 +79,8 @@ export class RspackDevServer extends WebpackDevServer {
? this.compiler.compilers
: [this.compiler];

const compilerForDev = compilers[0];

for (const compiler of compilers) {
const mode = compiler.options.mode || process.env.NODE_ENV;
if (this.options.hot) {
Expand All @@ -100,6 +102,22 @@ export class RspackDevServer extends WebpackDevServer {

// @ts-expect-error
await super.initialize();

// now we have the exact URI
this.defineDevServerUri(compilerForDev);
}

defineDevServerUri(compiler: Compiler) {
new DefinePlugin({
__rspack_dev_server_uri: JSON.stringify(this.getDevServerUri())
}).apply(compiler);
}

getDevServerUri() {
const protocol = this.options.server.type;
const hostname = this.options.host || "127.0.0.1";
const port = this.options.port;
return `${protocol}://${hostname}:${port}`;
}

getClientEntry(): string {
Expand Down