@rspack/dev-server 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/index.js +51 -14
- package/dist/alias.d.ts +2 -0
- package/dist/alias.js +36 -0
- package/dist/server.d.ts +1 -4
- package/dist/server.js +34 -282
- package/package.json +11 -4
package/client/index.js
CHANGED
|
@@ -106,6 +106,28 @@ var status = {
|
|
|
106
106
|
currentHash: typeof __webpack_hash__ !== "undefined" ? __webpack_hash__ : ""
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
+
var decodeOverlayOptions = function decodeOverlayOptions(overlayOptions) {
|
|
110
|
+
if (typeof overlayOptions === "object") {
|
|
111
|
+
["warnings", "errors", "runtimeErrors"].forEach(function (property) {
|
|
112
|
+
if (typeof overlayOptions[property] === "string") {
|
|
113
|
+
var overlayFilterFunctionString = decodeURIComponent(
|
|
114
|
+
overlayOptions[property]
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// eslint-disable-next-line no-new-func
|
|
118
|
+
var overlayFilterFunction = new Function(
|
|
119
|
+
"message",
|
|
120
|
+
"var callback = ".concat(
|
|
121
|
+
overlayFilterFunctionString,
|
|
122
|
+
"\n return callback(message)"
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
overlayOptions[property] = overlayFilterFunction;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
109
131
|
/** @type {Options} */
|
|
110
132
|
var options = {
|
|
111
133
|
hot: false,
|
|
@@ -132,6 +154,7 @@ if (parsedResourceQuery.progress === "true") {
|
|
|
132
154
|
options.progress = true;
|
|
133
155
|
enabledFeatures.Progress = true;
|
|
134
156
|
}
|
|
157
|
+
|
|
135
158
|
if (parsedResourceQuery.overlay) {
|
|
136
159
|
try {
|
|
137
160
|
options.overlay = JSON.parse(parsedResourceQuery.overlay);
|
|
@@ -149,6 +172,7 @@ if (parsedResourceQuery.overlay) {
|
|
|
149
172
|
},
|
|
150
173
|
options.overlay
|
|
151
174
|
);
|
|
175
|
+
decodeOverlayOptions(options.overlay);
|
|
152
176
|
}
|
|
153
177
|
enabledFeatures.Overlay = true;
|
|
154
178
|
}
|
|
@@ -232,6 +256,7 @@ var onSocketMessage = {
|
|
|
232
256
|
return;
|
|
233
257
|
}
|
|
234
258
|
options.overlay = value;
|
|
259
|
+
decodeOverlayOptions(options.overlay);
|
|
235
260
|
},
|
|
236
261
|
/**
|
|
237
262
|
* @param {number} value
|
|
@@ -321,16 +346,22 @@ var onSocketMessage = {
|
|
|
321
346
|
for (var i = 0; i < printableWarnings.length; i++) {
|
|
322
347
|
log.warn(printableWarnings[i]);
|
|
323
348
|
}
|
|
324
|
-
var
|
|
349
|
+
var overlayWarningsSetting =
|
|
325
350
|
typeof options.overlay === "boolean"
|
|
326
351
|
? options.overlay
|
|
327
352
|
: options.overlay && options.overlay.warnings;
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
353
|
+
if (overlayWarningsSetting) {
|
|
354
|
+
var warningsToDisplay =
|
|
355
|
+
typeof overlayWarningsSetting === "function"
|
|
356
|
+
? _warnings.filter(overlayWarningsSetting)
|
|
357
|
+
: _warnings;
|
|
358
|
+
if (warningsToDisplay.length) {
|
|
359
|
+
overlay.send({
|
|
360
|
+
type: "BUILD_ERROR",
|
|
361
|
+
level: "warning",
|
|
362
|
+
messages: _warnings
|
|
363
|
+
});
|
|
364
|
+
}
|
|
334
365
|
}
|
|
335
366
|
if (params && params.preventReloading) {
|
|
336
367
|
return;
|
|
@@ -352,16 +383,22 @@ var onSocketMessage = {
|
|
|
352
383
|
for (var i = 0; i < printableErrors.length; i++) {
|
|
353
384
|
log.error(printableErrors[i]);
|
|
354
385
|
}
|
|
355
|
-
var
|
|
386
|
+
var overlayErrorsSettings =
|
|
356
387
|
typeof options.overlay === "boolean"
|
|
357
388
|
? options.overlay
|
|
358
389
|
: options.overlay && options.overlay.errors;
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
390
|
+
if (overlayErrorsSettings) {
|
|
391
|
+
var errorsToDisplay =
|
|
392
|
+
typeof overlayErrorsSettings === "function"
|
|
393
|
+
? _errors.filter(overlayErrorsSettings)
|
|
394
|
+
: _errors;
|
|
395
|
+
if (errorsToDisplay.length) {
|
|
396
|
+
overlay.send({
|
|
397
|
+
type: "BUILD_ERROR",
|
|
398
|
+
level: "error",
|
|
399
|
+
messages: _errors
|
|
400
|
+
});
|
|
401
|
+
}
|
|
365
402
|
}
|
|
366
403
|
},
|
|
367
404
|
/**
|
package/dist/alias.d.ts
ADDED
package/dist/alias.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeResolveAlias = exports.addResolveAlias = void 0;
|
|
4
|
+
const RESOLVER_MAP = {};
|
|
5
|
+
const addResolveAlias = (name, aliasMap) => {
|
|
6
|
+
const modulePath = require.resolve(name);
|
|
7
|
+
if (RESOLVER_MAP[modulePath]) {
|
|
8
|
+
throw new Error(`Should not add resolve alias to ${name} again.`);
|
|
9
|
+
}
|
|
10
|
+
const m = require.cache[modulePath];
|
|
11
|
+
if (!m) {
|
|
12
|
+
throw new Error("Failed to resolve webpack-dev-server.");
|
|
13
|
+
}
|
|
14
|
+
RESOLVER_MAP[modulePath] = m.require.resolve;
|
|
15
|
+
m.require.resolve = ((id, options) => aliasMap[id] ||
|
|
16
|
+
RESOLVER_MAP[modulePath].apply(m.require, [
|
|
17
|
+
id,
|
|
18
|
+
options
|
|
19
|
+
]));
|
|
20
|
+
};
|
|
21
|
+
exports.addResolveAlias = addResolveAlias;
|
|
22
|
+
const removeResolveAlias = (name) => {
|
|
23
|
+
const modulePath = require.resolve(name);
|
|
24
|
+
if (!RESOLVER_MAP[modulePath]) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const m = require.cache[modulePath];
|
|
28
|
+
if (!m) {
|
|
29
|
+
throw new Error("Failed to resolve webpack-dev-server");
|
|
30
|
+
}
|
|
31
|
+
if (RESOLVER_MAP[modulePath]) {
|
|
32
|
+
m.require.resolve = RESOLVER_MAP[modulePath];
|
|
33
|
+
delete RESOLVER_MAP[modulePath];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.removeResolveAlias = removeResolveAlias;
|
package/dist/server.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { FSWatcher } from "chokidar";
|
|
|
7
7
|
import WebpackDevServer from "webpack-dev-server";
|
|
8
8
|
import type { DevServer, ResolvedDevServer } from "./config";
|
|
9
9
|
export declare class RspackDevServer extends WebpackDevServer {
|
|
10
|
-
static getFreePort(port: string, host: string)
|
|
10
|
+
static getFreePort: (port: string, host: string) => Promise<any>;
|
|
11
11
|
/**
|
|
12
12
|
* resolved after `normalizedOptions`
|
|
13
13
|
*/
|
|
@@ -20,9 +20,6 @@ export declare class RspackDevServer extends WebpackDevServer {
|
|
|
20
20
|
webSocketServer: WebpackDevServer.WebSocketServerImplementation | undefined;
|
|
21
21
|
static version: string;
|
|
22
22
|
constructor(options: DevServer, compiler: Compiler | MultiCompiler);
|
|
23
|
-
private getClientTransport;
|
|
24
23
|
initialize(): Promise<void>;
|
|
25
|
-
private setupDevMiddleware;
|
|
26
|
-
private setupMiddlewares;
|
|
27
24
|
private addAdditionalEntries;
|
|
28
25
|
}
|
package/dist/server.js
CHANGED
|
@@ -15,87 +15,35 @@ exports.RspackDevServer = void 0;
|
|
|
15
15
|
*/
|
|
16
16
|
const node_path_1 = __importDefault(require("node:path"));
|
|
17
17
|
const core_1 = require("@rspack/core");
|
|
18
|
-
const webpack_dev_middleware_1 = __importDefault(require("webpack-dev-middleware"));
|
|
19
18
|
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
20
19
|
// @ts-ignore 'package.json' is not under 'rootDir'
|
|
21
20
|
const package_json_1 = require("../package.json");
|
|
21
|
+
const alias_1 = require("./alias");
|
|
22
22
|
const patch_1 = require("./patch");
|
|
23
23
|
(0, patch_1.applyDevServerPatch)();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return port;
|
|
28
|
-
}
|
|
29
|
-
const pRetry = require("p-retry");
|
|
30
|
-
const getPort = require("webpack-dev-server/lib/getPort");
|
|
31
|
-
const basePort = typeof process.env.WEBPACK_DEV_SERVER_BASE_PORT !== "undefined"
|
|
32
|
-
? Number.parseInt(process.env.WEBPACK_DEV_SERVER_BASE_PORT, 10)
|
|
33
|
-
: 8080;
|
|
34
|
-
// Try to find unused port and listen on it for 3 times,
|
|
35
|
-
// if port is not specified in options.
|
|
36
|
-
const defaultPortRetry = typeof process.env.WEBPACK_DEV_SERVER_PORT_RETRY !== "undefined"
|
|
37
|
-
? Number.parseInt(process.env.WEBPACK_DEV_SERVER_PORT_RETRY, 10)
|
|
38
|
-
: 3;
|
|
39
|
-
return pRetry(() => getPort(basePort, host), {
|
|
40
|
-
retries: defaultPortRetry
|
|
41
|
-
});
|
|
24
|
+
const getFreePort = async function getFreePort(port, host) {
|
|
25
|
+
if (typeof port !== "undefined" && port !== null && port !== "auto") {
|
|
26
|
+
return port;
|
|
42
27
|
}
|
|
28
|
+
const pRetry = require("p-retry");
|
|
29
|
+
const getPort = require("webpack-dev-server/lib/getPort");
|
|
30
|
+
const basePort = typeof process.env.WEBPACK_DEV_SERVER_BASE_PORT !== "undefined"
|
|
31
|
+
? Number.parseInt(process.env.WEBPACK_DEV_SERVER_BASE_PORT, 10)
|
|
32
|
+
: 8080;
|
|
33
|
+
// Try to find unused port and listen on it for 3 times,
|
|
34
|
+
// if port is not specified in options.
|
|
35
|
+
const defaultPortRetry = typeof process.env.WEBPACK_DEV_SERVER_PORT_RETRY !== "undefined"
|
|
36
|
+
? Number.parseInt(process.env.WEBPACK_DEV_SERVER_PORT_RETRY, 10)
|
|
37
|
+
: 3;
|
|
38
|
+
return pRetry(() => getPort(basePort, host), {
|
|
39
|
+
retries: defaultPortRetry
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
webpack_dev_server_1.default.getFreePort = getFreePort;
|
|
43
|
+
class RspackDevServer extends webpack_dev_server_1.default {
|
|
43
44
|
constructor(options, compiler) {
|
|
44
45
|
super(options, compiler);
|
|
45
|
-
|
|
46
|
-
getClientTransport() {
|
|
47
|
-
// WARNING: we can't use `super.getClientTransport`,
|
|
48
|
-
// because we doesn't had same directory structure.
|
|
49
|
-
let clientImplementation;
|
|
50
|
-
let clientImplementationFound = true;
|
|
51
|
-
const isKnownWebSocketServerImplementation = this.options.webSocketServer &&
|
|
52
|
-
typeof this.options.webSocketServer.type === "string" &&
|
|
53
|
-
(this.options.webSocketServer.type === "ws" ||
|
|
54
|
-
this.options.webSocketServer.type === "sockjs");
|
|
55
|
-
let clientTransport;
|
|
56
|
-
if (this.options.client) {
|
|
57
|
-
if (typeof this.options.client.webSocketTransport !== "undefined") {
|
|
58
|
-
clientTransport = this.options.client.webSocketTransport;
|
|
59
|
-
}
|
|
60
|
-
else if (isKnownWebSocketServerImplementation) {
|
|
61
|
-
// @ts-expect-error: TS cannot infer webSocketServer is narrowed
|
|
62
|
-
clientTransport = this.options.webSocketServer.type;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
clientTransport = "ws";
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
clientTransport = "ws";
|
|
70
|
-
}
|
|
71
|
-
switch (typeof clientTransport) {
|
|
72
|
-
case "string":
|
|
73
|
-
// could be 'sockjs', 'ws', or a path that should be required
|
|
74
|
-
if (clientTransport === "sockjs") {
|
|
75
|
-
clientImplementation = require.resolve("webpack-dev-server/client/clients/SockJSClient");
|
|
76
|
-
}
|
|
77
|
-
else if (clientTransport === "ws") {
|
|
78
|
-
clientImplementation = require.resolve("webpack-dev-server/client/clients/WebSocketClient");
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
try {
|
|
82
|
-
clientImplementation = require.resolve(clientTransport);
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
clientImplementationFound = false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
default:
|
|
90
|
-
clientImplementationFound = false;
|
|
91
|
-
}
|
|
92
|
-
if (!clientImplementationFound) {
|
|
93
|
-
throw new Error(`${!isKnownWebSocketServerImplementation
|
|
94
|
-
? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. "
|
|
95
|
-
: ""}client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class `);
|
|
96
|
-
}
|
|
97
|
-
// @ts-expect-error
|
|
98
|
-
return clientImplementation;
|
|
46
|
+
// override
|
|
99
47
|
}
|
|
100
48
|
async initialize() {
|
|
101
49
|
const compilers = this.compiler instanceof core_1.MultiCompiler
|
|
@@ -108,227 +56,31 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
108
56
|
this.logger.warn("Hot Module Replacement (HMR) is enabled for the production build. \n" +
|
|
109
57
|
"Make sure to disable HMR for production by setting `devServer.hot` to `false` in the configuration.");
|
|
110
58
|
}
|
|
111
|
-
const HMRPluginExists = compiler.options.plugins.find(p => p?.constructor === compiler.webpack.HotModuleReplacementPlugin);
|
|
112
|
-
if (HMRPluginExists) {
|
|
113
|
-
this.logger.warn(`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`);
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
// Apply the HMR plugin
|
|
117
|
-
const plugin = new compiler.webpack.HotModuleReplacementPlugin();
|
|
118
|
-
plugin.apply(compiler);
|
|
119
|
-
}
|
|
120
|
-
// Apply modified version of `ansi-html-community`
|
|
121
59
|
compiler.options.resolve.alias = {
|
|
122
60
|
"ansi-html-community": node_path_1.default.resolve(__dirname, "./ansiHTML"),
|
|
123
61
|
...compiler.options.resolve.alias
|
|
124
62
|
};
|
|
125
63
|
}
|
|
126
64
|
}
|
|
127
|
-
if (this.options.webSocketServer) {
|
|
128
|
-
for (const compiler of compilers) {
|
|
129
|
-
this.addAdditionalEntries(compiler);
|
|
130
|
-
new compiler.webpack.ProvidePlugin({
|
|
131
|
-
__webpack_dev_server_client__: this.getClientTransport()
|
|
132
|
-
}).apply(compiler);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// @ts-expect-error: `setupHooks` is private function in base class.
|
|
136
|
-
this.setupHooks();
|
|
137
|
-
// @ts-expect-error: `setupApp` is private function in base class.
|
|
138
|
-
this.setupApp();
|
|
139
|
-
// @ts-expect-error: `setupHostHeaderCheck` is private function in base class.
|
|
140
|
-
this.setupHostHeaderCheck();
|
|
141
|
-
this.setupDevMiddleware();
|
|
142
|
-
// @ts-expect-error: `setupBuiltInRoutes` is private function in base class.
|
|
143
|
-
this.setupBuiltInRoutes();
|
|
144
|
-
// @ts-expect-error: `setupWatchFiles` is private function in base class.
|
|
145
|
-
this.setupWatchFiles();
|
|
146
|
-
// @ts-expect-error: `setupWatchStaticFiles` is private function in base class.
|
|
147
|
-
this.setupWatchStaticFiles();
|
|
148
|
-
this.setupMiddlewares();
|
|
149
|
-
// @ts-expect-error: `createServer` is private function in base class.
|
|
150
|
-
this.createServer();
|
|
151
|
-
if (this.options.setupExitSignals) {
|
|
152
|
-
const signals = ["SIGINT", "SIGTERM"];
|
|
153
|
-
let needForceShutdown = false;
|
|
154
|
-
for (const signal of signals) {
|
|
155
|
-
const listener = () => {
|
|
156
|
-
if (needForceShutdown) {
|
|
157
|
-
process.exit();
|
|
158
|
-
}
|
|
159
|
-
this.logger.info("Gracefully shutting down. To force exit, press ^C again. Please wait...");
|
|
160
|
-
needForceShutdown = true;
|
|
161
|
-
this.stopCallback(() => {
|
|
162
|
-
if (typeof this.compiler.close === "function") {
|
|
163
|
-
this.compiler.close(() => {
|
|
164
|
-
process.exit();
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
process.exit();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
// @ts-expect-error: `listeners` is private function in base class.
|
|
173
|
-
this.listeners.push({ name: signal, listener });
|
|
174
|
-
process.on(signal, listener);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// Proxy WebSocket without the initial http request
|
|
178
|
-
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
|
|
179
|
-
// @ts-expect-error: `webSocketProxies` is private function in base class.
|
|
180
|
-
for (const webSocketProxy of this.webSocketProxies) {
|
|
181
|
-
this.server.on("upgrade", webSocketProxy.upgrade);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
setupDevMiddleware() {
|
|
185
|
-
// @ts-expect-error
|
|
186
|
-
this.middleware = (0, webpack_dev_middleware_1.default)(this.compiler, this.options.devMiddleware);
|
|
187
|
-
}
|
|
188
|
-
setupMiddlewares() {
|
|
189
|
-
const middlewares = [];
|
|
190
|
-
for (const middleware of middlewares) {
|
|
191
|
-
if (typeof middleware === "function") {
|
|
192
|
-
// @ts-expect-error
|
|
193
|
-
this.app.use(middleware);
|
|
194
|
-
}
|
|
195
|
-
else if (typeof middleware.path !== "undefined") {
|
|
196
|
-
// @ts-expect-error
|
|
197
|
-
this.app.use(middleware.path, middleware.middleware);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
// @ts-expect-error
|
|
201
|
-
this.app.use(middleware.middleware);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
65
|
// @ts-expect-error
|
|
205
|
-
super.
|
|
66
|
+
await super.initialize();
|
|
206
67
|
}
|
|
68
|
+
// @ts-ignore
|
|
207
69
|
addAdditionalEntries(compiler) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
.webSocketURL;
|
|
217
|
-
const webSocketServer = this.options.webSocketServer;
|
|
218
|
-
const searchParams = new URLSearchParams();
|
|
219
|
-
let protocol;
|
|
220
|
-
// We are proxying dev server and need to specify custom `hostname`
|
|
221
|
-
if (typeof webSocketURL.protocol !== "undefined") {
|
|
222
|
-
protocol = webSocketURL.protocol;
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
protocol = this.options.server.type === "http" ? "ws:" : "wss:";
|
|
226
|
-
}
|
|
227
|
-
searchParams.set("protocol", protocol);
|
|
228
|
-
if (typeof webSocketURL.username !== "undefined") {
|
|
229
|
-
searchParams.set("username", webSocketURL.username);
|
|
230
|
-
}
|
|
231
|
-
if (typeof webSocketURL.password !== "undefined") {
|
|
232
|
-
searchParams.set("password", webSocketURL.password);
|
|
233
|
-
}
|
|
234
|
-
let hostname;
|
|
235
|
-
// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
|
|
236
|
-
// TODO show warning about this
|
|
237
|
-
const isSockJSType = webSocketServer.type === "sockjs";
|
|
238
|
-
// We are proxying dev server and need to specify custom `hostname`
|
|
239
|
-
if (typeof webSocketURL.hostname !== "undefined") {
|
|
240
|
-
hostname = webSocketURL.hostname;
|
|
241
|
-
}
|
|
242
|
-
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
|
|
243
|
-
else if (typeof webSocketServer.options?.host !== "undefined" &&
|
|
244
|
-
!isSockJSType) {
|
|
245
|
-
hostname = webSocketServer.options.host;
|
|
246
|
-
}
|
|
247
|
-
// The `host` option is specified
|
|
248
|
-
else if (typeof this.options.host !== "undefined") {
|
|
249
|
-
hostname = this.options.host;
|
|
250
|
-
}
|
|
251
|
-
// The `port` option is not specified
|
|
252
|
-
else {
|
|
253
|
-
hostname = "0.0.0.0";
|
|
254
|
-
}
|
|
255
|
-
searchParams.set("hostname", hostname);
|
|
256
|
-
let port;
|
|
257
|
-
// We are proxying dev server and need to specify custom `port`
|
|
258
|
-
if (typeof webSocketURL.port !== "undefined") {
|
|
259
|
-
port = webSocketURL.port;
|
|
260
|
-
}
|
|
261
|
-
// Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
|
|
262
|
-
else if (typeof webSocketServer.options?.port !== "undefined" &&
|
|
263
|
-
!isSockJSType) {
|
|
264
|
-
port = webSocketServer.options.port;
|
|
265
|
-
}
|
|
266
|
-
// The `port` option is specified
|
|
267
|
-
else if (typeof this.options.port === "number") {
|
|
268
|
-
port = this.options.port;
|
|
269
|
-
}
|
|
270
|
-
// The `port` option is specified using `string`
|
|
271
|
-
else if (typeof this.options.port === "string" &&
|
|
272
|
-
this.options.port !== "auto") {
|
|
273
|
-
port = Number(this.options.port);
|
|
274
|
-
}
|
|
275
|
-
// The `port` option is not specified or set to `auto`
|
|
276
|
-
else {
|
|
277
|
-
port = "0";
|
|
278
|
-
}
|
|
279
|
-
searchParams.set("port", String(port));
|
|
280
|
-
let pathname = "";
|
|
281
|
-
// We are proxying dev server and need to specify custom `pathname`
|
|
282
|
-
if (typeof webSocketURL.pathname !== "undefined") {
|
|
283
|
-
pathname = webSocketURL.pathname;
|
|
284
|
-
}
|
|
285
|
-
// Web socket server works on custom `path`
|
|
286
|
-
else if (typeof webSocketServer.options?.prefix !== "undefined" ||
|
|
287
|
-
typeof webSocketServer.options?.path !== "undefined") {
|
|
288
|
-
pathname =
|
|
289
|
-
webSocketServer.options.prefix || webSocketServer.options.path;
|
|
290
|
-
}
|
|
291
|
-
searchParams.set("pathname", pathname);
|
|
292
|
-
const client = /** @type {ClientConfiguration} */ this.options.client;
|
|
293
|
-
if (typeof client.logging !== "undefined") {
|
|
294
|
-
searchParams.set("logging", client.logging);
|
|
295
|
-
}
|
|
296
|
-
if (typeof client.progress !== "undefined") {
|
|
297
|
-
searchParams.set("progress", String(client.progress));
|
|
298
|
-
}
|
|
299
|
-
if (typeof client.overlay !== "undefined") {
|
|
300
|
-
searchParams.set("overlay", typeof client.overlay === "boolean"
|
|
301
|
-
? String(client.overlay)
|
|
302
|
-
: JSON.stringify(client.overlay));
|
|
303
|
-
}
|
|
304
|
-
if (typeof client.reconnect !== "undefined") {
|
|
305
|
-
searchParams.set("reconnect", typeof client.reconnect === "number"
|
|
306
|
-
? String(client.reconnect)
|
|
307
|
-
: "10");
|
|
308
|
-
}
|
|
309
|
-
if (typeof this.options.hot !== "undefined") {
|
|
310
|
-
searchParams.set("hot", String(this.options.hot));
|
|
311
|
-
}
|
|
312
|
-
if (typeof this.options.liveReload !== "undefined") {
|
|
313
|
-
searchParams.set("live-reload", String(this.options.liveReload));
|
|
314
|
-
}
|
|
315
|
-
webSocketURLStr = searchParams.toString();
|
|
316
|
-
}
|
|
317
|
-
additionalEntries.push(`${require.resolve("@rspack/dev-server/client/index")}?${webSocketURLStr}`);
|
|
318
|
-
}
|
|
319
|
-
if (this.options.hot === "only") {
|
|
320
|
-
additionalEntries.push(require.resolve("@rspack/core/hot/only-dev-server"));
|
|
321
|
-
}
|
|
322
|
-
else if (this.options.hot) {
|
|
323
|
-
additionalEntries.push(require.resolve("@rspack/core/hot/dev-server"));
|
|
70
|
+
(0, alias_1.addResolveAlias)("webpack-dev-server", {
|
|
71
|
+
"../client/index.js": require.resolve("@rspack/dev-server/client/index"),
|
|
72
|
+
"webpack/hot/only-dev-server": require.resolve("@rspack/core/hot/only-dev-server"),
|
|
73
|
+
"webpack/hot/dev-server": require.resolve("@rspack/core/hot/dev-server")
|
|
74
|
+
});
|
|
75
|
+
try {
|
|
76
|
+
// @ts-expect-error
|
|
77
|
+
super.addAdditionalEntries(compiler);
|
|
324
78
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
new webpack.EntryPlugin(compiler.context, additionalEntry, {
|
|
328
|
-
name: undefined
|
|
329
|
-
}).apply(compiler);
|
|
79
|
+
finally {
|
|
80
|
+
(0, alias_1.removeResolveAlias)("webpack-dev-server");
|
|
330
81
|
}
|
|
331
82
|
}
|
|
332
83
|
}
|
|
84
|
+
RspackDevServer.getFreePort = getFreePort;
|
|
333
85
|
RspackDevServer.version = package_json_1.version;
|
|
334
86
|
exports.RspackDevServer = RspackDevServer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/dev-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Development server for rspack",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,21 +29,27 @@
|
|
|
29
29
|
"directory": "packages/rspack-dev-server"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@jest/test-sequencer": "^29.7.0",
|
|
32
33
|
"@rspack/plugin-react-refresh": "1.0.0",
|
|
33
34
|
"@types/connect-history-api-fallback": "1.5.4",
|
|
34
35
|
"@types/express": "4.17.21",
|
|
35
36
|
"@types/mime-types": "2.1.4",
|
|
36
37
|
"@types/ws": "8.5.10",
|
|
38
|
+
"css-loader": "^6.11.0",
|
|
37
39
|
"graceful-fs": "4.2.10",
|
|
38
40
|
"http-proxy": "^1.18.1",
|
|
39
41
|
"jest-serializer-path": "^0.1.15",
|
|
42
|
+
"prettier": "3.2.5",
|
|
40
43
|
"puppeteer": "^23.2.2",
|
|
44
|
+
"require-from-string": "^2.0.2",
|
|
41
45
|
"sockjs-client": "^1.6.1",
|
|
46
|
+
"style-loader": "^3.3.3",
|
|
42
47
|
"supertest": "^6.1.3",
|
|
43
48
|
"tcp-port-used": "^1.0.2",
|
|
44
49
|
"typescript": "5.0.2",
|
|
45
|
-
"
|
|
46
|
-
"@rspack/
|
|
50
|
+
"wait-for-expect": "^3.0.2",
|
|
51
|
+
"@rspack/core": "1.0.6",
|
|
52
|
+
"@rspack/dev-server": "1.0.6"
|
|
47
53
|
},
|
|
48
54
|
"dependencies": {
|
|
49
55
|
"chokidar": "^3.6.0",
|
|
@@ -62,7 +68,8 @@
|
|
|
62
68
|
"scripts": {
|
|
63
69
|
"build": "tsc -b ./tsconfig.build.json",
|
|
64
70
|
"dev": "tsc -w -b ./tsconfig.build.json",
|
|
65
|
-
"test": "
|
|
71
|
+
"test:install": "cross-env ./node_modules/.bin/puppeteer browsers install chrome",
|
|
72
|
+
"test": "pnpm run test:install && cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --colors",
|
|
66
73
|
"api-extractor": "api-extractor run --verbose",
|
|
67
74
|
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
|
|
68
75
|
}
|