@rspack/dev-server 0.0.0-01dbf86423-20221210100716

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;AAaA,4CAAoB;AACpB,wDAAgC;AAChC,gDAAwB;AACxB,qCAAwC;AACxC,4EAAkD;AAClD,sDAA8B;AAE9B,4EAAyC;AACzC,6BAA6C;AAC7C,qCAA6C;AAc7C,+BAA+B;AAC/B,MAAa,eAAe;IAa3B,YAAmB,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;QACpC,IAAI,CAAC,MAAM,GAAG,IAAA,qBAAY,EAAC,mBAAmB,CAAC,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACjE,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC9B,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC3B,CAAC;IAED,gBAAgB,CAAC,MAAW,EAAE;QAC7B,OAAO,IAAA,0BAAiB,EAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,sBAAsB;;QACrB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE;YAC1C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAC;SAC1C;QACD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,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,CAAC,CAAC;QAEH,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACvB,IAAI,CAAC,CAAC,IAAI,EAAE;gBACX,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;aACnC;iBAAM;gBACN,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;aAC3B;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,YAAY;QACnB,IAAI,CAAC,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAEO,UAAU;QACjB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;YAClD,eAAe;YACf,IAAI,IAAI,CAAC,eAAe,EAAE;gBACzB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,kBAAkB;aACxE;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AA/WD,0CA+WC"}
package/dist/ws.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { RspackDevServer } from "./server";
2
+ import WebSocket from "ws";
3
+ export declare type ClientConnection = WebSocket & {
4
+ isAlive?: boolean;
5
+ };
6
+ export interface WebSocketServer {
7
+ heartbeatInterval: number;
8
+ implementation: WebSocket.Server<WebSocket.WebSocket>;
9
+ server: RspackDevServer;
10
+ clients: ClientConnection[];
11
+ }
12
+ export declare function createWebsocketServer(server: RspackDevServer): WebSocketServer;
13
+ //# sourceMappingURL=ws.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,SAAS,MAAM,IAAI,CAAC;AAG3B,oBAAY,gBAAgB,GAAG,SAAS,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjE,MAAM,WAAW,eAAe;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAED,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,eAAe,GACrB,eAAe,CAEjB"}
package/dist/ws.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createWebsocketServer = void 0;
7
+ const WebsocketServer_1 = __importDefault(require("webpack-dev-server/lib/servers/WebsocketServer"));
8
+ function createWebsocketServer(server) {
9
+ return new WebsocketServer_1.default(server);
10
+ }
11
+ exports.createWebsocketServer = createWebsocketServer;
12
+ //# sourceMappingURL=ws.js.map
package/dist/ws.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.js","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":";;;;;;AAEA,qGAA6E;AAW7E,SAAgB,qBAAqB,CACpC,MAAuB;IAEvB,OAAO,IAAI,yBAAe,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAJD,sDAIC"}
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ preset: "ts-jest",
4
+ testEnvironment: "node",
5
+ testMatch: ["<rootDir>/tests/*.test.ts"],
6
+ cache: false
7
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@rspack/dev-server",
3
+ "description": "",
4
+ "version": "0.0.0-01dbf86423-20221210100716",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "author": "",
8
+ "license": "ISC",
9
+ "devDependencies": {
10
+ "tsm": "^2.2.2",
11
+ "typescript": "^4.7.4",
12
+ "@types/node": "16.11.7",
13
+ "@types/express": "4.17.14",
14
+ "@types/connect-history-api-fallback": "1.3.5",
15
+ "@rspack/core": "0.0.0-01dbf86423-20221210100716"
16
+ },
17
+ "dependencies": {
18
+ "express": "4.18.1",
19
+ "chokidar": "3.5.3",
20
+ "ws": "8.8.1",
21
+ "webpack-dev-server": "4.11.1",
22
+ "connect-history-api-fallback": "2.0.0",
23
+ "http-proxy-middleware": "2.0.6",
24
+ "@rspack/dev-middleware": "0.0.0-01dbf86423-20221210100716",
25
+ "@rspack/dev-client": "0.0.0-01dbf86423-20221210100716",
26
+ "@rspack/dev-server": "0.0.0-01dbf86423-20221210100716"
27
+ },
28
+ "peerDependencies": {
29
+ "@rspack/core": "0.0.0-01dbf86423-20221210100716"
30
+ },
31
+ "scripts": {
32
+ "build": "rm -rf lib/ && tsc",
33
+ "dev": "tsc -w",
34
+ "test": "jest --verbose"
35
+ }
36
+ }
package/src/config.ts ADDED
@@ -0,0 +1,72 @@
1
+ import type {
2
+ Dev,
3
+ WebSocketServerOptions,
4
+ RspackOptionsNormalized
5
+ } from "@rspack/core";
6
+ import type { WatchOptions } from "chokidar";
7
+ import path from "path";
8
+ import { resolveWatchOption } from "@rspack/core";
9
+ import { ProxyOptions } from "@rspack/core/src/config/devServer";
10
+
11
+ export interface ResolvedDev {
12
+ host: string;
13
+ port: number;
14
+ static: {
15
+ directory: string;
16
+ watch: false | WatchOptions;
17
+ };
18
+ devMiddleware: {};
19
+ hot: boolean;
20
+ open: boolean;
21
+ liveReload: boolean;
22
+ webSocketServer: false | WebSocketServerOptions;
23
+ proxy: ProxyOptions;
24
+ }
25
+
26
+ export function resolveDevOptions(
27
+ devConfig: Dev,
28
+ compilerOptions: RspackOptionsNormalized
29
+ ): ResolvedDev {
30
+ const open = true;
31
+ const proxy = devConfig.proxy;
32
+ const hot = devConfig.hot ?? true;
33
+ // --- static
34
+ const directory =
35
+ devConfig.static?.directory ??
36
+ path.resolve(compilerOptions.context, compilerOptions.output.path);
37
+ let watch: false | WatchOptions = {};
38
+ if (devConfig.static?.watch === false) {
39
+ watch = false;
40
+ } else if (devConfig.static?.watch === true) {
41
+ watch = resolveWatchOption({});
42
+ } else if (devConfig.static?.watch) {
43
+ watch = devConfig.static?.watch;
44
+ }
45
+ // ---
46
+ const devMiddleware = devConfig.devMiddleware ?? {};
47
+ const liveReload = devConfig.liveReload ?? true;
48
+
49
+ let webSocketServer: false | WebSocketServerOptions = {};
50
+ if (devConfig.webSocketServer === false) {
51
+ webSocketServer = false;
52
+ } else if (devConfig.webSocketServer === true) {
53
+ webSocketServer = {};
54
+ } else if (devConfig.webSocketServer) {
55
+ webSocketServer = devConfig.webSocketServer;
56
+ }
57
+
58
+ return {
59
+ host: devConfig.host,
60
+ port: devConfig.port ? Number(devConfig.port) : undefined,
61
+ static: {
62
+ directory,
63
+ watch
64
+ },
65
+ devMiddleware,
66
+ open,
67
+ hot,
68
+ liveReload,
69
+ webSocketServer,
70
+ proxy
71
+ };
72
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { RspackDevServer } from "./server";
package/src/logger.ts ADDED
@@ -0,0 +1,30 @@
1
+ export interface Logger {
2
+ error(...args: any[]): void;
3
+ warn(...args: any[]): void;
4
+ info(...args: any[]): void;
5
+ }
6
+
7
+ const COLOR = {
8
+ RESET: "\x1b[0m",
9
+ //
10
+ RED: "\x1b[31m",
11
+ GREEN: "\x1b[32m",
12
+ YELLOW: "\x1b[33m"
13
+ };
14
+
15
+ export function createLogger(name: string): Logger {
16
+ if (!name.length) {
17
+ throw Error();
18
+ }
19
+ return {
20
+ error(...msgs: any[]) {
21
+ console.log("[", name, "]:", COLOR.RED, msgs, COLOR.RESET);
22
+ },
23
+ warn(...msgs: any[]) {
24
+ console.log("[", name, "]:", COLOR.YELLOW, msgs, COLOR.RESET);
25
+ },
26
+ info(...msgs: any[]) {
27
+ console.log("[", name, "]:", COLOR.GREEN, msgs, COLOR.RESET);
28
+ }
29
+ };
30
+ }
package/src/reload.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { RspackOptionsNormalized } from "@rspack/core";
2
+
3
+ interface Status {
4
+ isUnloading: boolean;
5
+ currentHash: string;
6
+ previousHash: string[];
7
+ }
8
+
9
+ export function reloadApp(
10
+ { liveReload, hot }: RspackOptionsNormalized["devServer"],
11
+ status: Status
12
+ ) {
13
+ if (status.isUnloading) {
14
+ return;
15
+ }
16
+
17
+ function applyReload(rootWindow: Window, intervalId: number) {
18
+ clearInterval(intervalId);
19
+ console.log("App update, Reloading...");
20
+ rootWindow.location.reload();
21
+ }
22
+
23
+ if (liveReload) {
24
+ let rootWindow = self;
25
+ const intervalId = self.setInterval(() => {
26
+ if (rootWindow.location.protocol !== "about:") {
27
+ applyReload(rootWindow, intervalId);
28
+ }
29
+ });
30
+ }
31
+ }
package/src/server.ts ADDED
@@ -0,0 +1,405 @@
1
+ import type { Compiler, Dev, RspackOptionsNormalized } from "@rspack/core";
2
+ import type { Logger } from "./logger";
3
+ import type { Socket } from "net";
4
+ import type { FSWatcher, WatchOptions } from "chokidar";
5
+ import type { WebSocketServer, ClientConnection } from "./ws";
6
+ import type {
7
+ Application,
8
+ RequestHandler as ExpressRequestHandler,
9
+ ErrorRequestHandler as ExpressErrorRequestHandler
10
+ } from "express";
11
+ import type { DevMiddleware } from "@rspack/dev-middleware";
12
+ import type { Server } from "http";
13
+ import type { ResolvedDev } from "./config";
14
+ import fs from "fs";
15
+ import chokidar from "chokidar";
16
+ import http from "http";
17
+ import { createLogger } from "./logger";
18
+ import WebpackDevServer from "webpack-dev-server";
19
+ import express from "express";
20
+
21
+ import rdm from "@rspack/dev-middleware";
22
+ import { createWebsocketServer } from "./ws";
23
+ import { resolveDevOptions } from "./config";
24
+
25
+ interface Middleware {
26
+ name?: string;
27
+ path?: string;
28
+ middleware: ExpressErrorRequestHandler | ExpressRequestHandler;
29
+ }
30
+ interface Listener {
31
+ name: string | Symbol;
32
+ listener: (...args: any) => void;
33
+ }
34
+ type Host = "local-ip" | "local-ipv4" | "local-ipv6" | string;
35
+ type Port = number | string | "auto";
36
+
37
+ // copy from webpack-dev-server
38
+ export class RspackDevServer {
39
+ options: ResolvedDev;
40
+ logger: Logger;
41
+ staticWatchers: FSWatcher[];
42
+ sockets: Socket[];
43
+ app: Application;
44
+ server: Server;
45
+ private listeners: Listener[];
46
+ private currentHash: string;
47
+ private middleware: DevMiddleware | undefined;
48
+ // TODO: now only support 'ws'
49
+ webSocketServer: WebSocketServer | undefined;
50
+
51
+ constructor(public compiler: Compiler) {
52
+ this.logger = createLogger("rspack-dev-server");
53
+ this.staticWatchers = [];
54
+ this.listeners = [];
55
+ this.sockets = [];
56
+ this.currentHash = "";
57
+ this.options = this.normalizeOptions(compiler.options.devServer);
58
+ this.rewriteCompilerOptions();
59
+ this.addAdditionEntires();
60
+ }
61
+
62
+ normalizeOptions(dev: Dev = {}) {
63
+ return resolveDevOptions(dev, this.compiler.options);
64
+ }
65
+
66
+ rewriteCompilerOptions() {
67
+ if (!this.compiler.options.builtins.react) {
68
+ this.compiler.options.builtins.react = {};
69
+ }
70
+ this.compiler.options.builtins.react.development =
71
+ this.compiler.options.builtins.react.development ?? true;
72
+ if (this.options.hot) {
73
+ this.compiler.options.builtins.react.refresh =
74
+ this.compiler.options.builtins.react.refresh ?? true;
75
+ }
76
+ }
77
+
78
+ addAdditionEntires() {
79
+ const entries: string[] = [];
80
+
81
+ if (this.options.hot) {
82
+ const hotUpdateEntryPath = require.resolve(
83
+ "@rspack/dev-client/devServer"
84
+ );
85
+ entries.push(hotUpdateEntryPath);
86
+
87
+ if (this.compiler.options.builtins.react?.refresh) {
88
+ const reactRefreshEntryPath = require.resolve(
89
+ "@rspack/dev-client/react-refresh"
90
+ );
91
+ entries.push(reactRefreshEntryPath);
92
+ }
93
+ }
94
+
95
+ const devClientEntryPath = require.resolve("@rspack/dev-client");
96
+ entries.push(devClientEntryPath);
97
+ for (const key in this.compiler.options.entry) {
98
+ this.compiler.options.entry[key].import.unshift(...entries);
99
+ }
100
+ }
101
+
102
+ static isAbsoluteURL(URL: string): boolean {
103
+ return WebpackDevServer.isAbsoluteURL(URL);
104
+ }
105
+
106
+ static findIp(gateway: string): string | undefined {
107
+ return WebpackDevServer.findIp(gateway);
108
+ }
109
+
110
+ static async internalIP(family: "v6" | "v4"): Promise<string | undefined> {
111
+ return WebpackDevServer.internalIP(family);
112
+ }
113
+
114
+ static async internalIPSync(
115
+ family: "v6" | "v4"
116
+ ): Promise<string | undefined> {
117
+ return WebpackDevServer.internalIPSync(family);
118
+ }
119
+
120
+ static async getHostname(hostname?: Host): Promise<string> {
121
+ return WebpackDevServer.getHostname(hostname);
122
+ }
123
+
124
+ static async getFreePort(port: Port, host: string): Promise<string | number> {
125
+ return WebpackDevServer.getFreePort(port, host);
126
+ }
127
+
128
+ static findCacheDir(): string {
129
+ // TODO: we need remove the `webpack-dev-server` tag in WebpackDevServer;
130
+ return "";
131
+ }
132
+
133
+ private getCompilerOptions(): RspackOptionsNormalized {
134
+ return this.compiler.options;
135
+ }
136
+
137
+ sendMessage(
138
+ clients: ClientConnection[],
139
+ type: string,
140
+ data?: any,
141
+ params?: any
142
+ ) {
143
+ for (const client of clients) {
144
+ if (client.readyState === 1) {
145
+ client.send(JSON.stringify({ type, data, params }));
146
+ }
147
+ }
148
+ }
149
+
150
+ watchFiles(watchPath: string | string[], watchOptions?: WatchOptions): void {
151
+ const watcher = chokidar.watch(watchPath, watchOptions);
152
+
153
+ // disabling refreshing on changing the content
154
+ if (this.options.liveReload) {
155
+ // TODO: remove this after we had memory filesystem
156
+ if (this.options.hot) {
157
+ return;
158
+ }
159
+
160
+ watcher.on("change", item => {
161
+ if (this.webSocketServer) {
162
+ this.sendMessage(
163
+ this.webSocketServer.clients,
164
+ "static-changed",
165
+ item
166
+ );
167
+ }
168
+ });
169
+ }
170
+
171
+ this.staticWatchers.push(watcher);
172
+ }
173
+
174
+ invalidate(callback = () => {}): void {
175
+ if (this.middleware) {
176
+ this.middleware.invalidate(callback);
177
+ }
178
+ }
179
+
180
+ async start(): Promise<void> {
181
+ this.setupHooks();
182
+ this.setupApp();
183
+ this.createServer();
184
+ this.setupWatchStaticFiles();
185
+ this.createWebsocketServer();
186
+ this.setupDevMiddleware();
187
+ this.setupMiddlewares();
188
+ const host = await RspackDevServer.getHostname(this.options.host);
189
+ const port = await RspackDevServer.getFreePort(this.options.port, host);
190
+ await new Promise(resolve =>
191
+ this.server.listen(
192
+ {
193
+ port,
194
+ host
195
+ },
196
+ () => {
197
+ this.logger.info(`Loopback: http://localhost:${port}`);
198
+ let internalIPv4 = WebpackDevServer.internalIPSync("v4");
199
+ this.logger.info(
200
+ `Your Network (IPV4) http://${internalIPv4}:${port}`
201
+ );
202
+ resolve({});
203
+ }
204
+ )
205
+ );
206
+ }
207
+
208
+ startCallback(callback?: (err?: Error) => void): void {
209
+ throw new Error("Method not implemented.");
210
+ }
211
+ stopCallback(callback?: (err?: Error) => void): void {
212
+ throw new Error("Method not implemented.");
213
+ }
214
+ listen(port: Port, hostname: string, fn: (err?: Error) => void): void {
215
+ throw new Error("Method not implemented.");
216
+ }
217
+ close(callback?: (err?: Error) => void): void {
218
+ throw new Error("Method not implemented.");
219
+ }
220
+
221
+ async stop(): Promise<void> {
222
+ await Promise.all(this.staticWatchers.map(watcher => watcher.close()));
223
+ this.middleware = null;
224
+ this.staticWatchers = [];
225
+ if (this.server) {
226
+ this.server.close();
227
+ }
228
+ if (this.webSocketServer) {
229
+ await new Promise(resolve => {
230
+ this.webSocketServer.implementation.close(() => {
231
+ resolve(void 0);
232
+ });
233
+ for (const client of this.webSocketServer.clients) client.terminate();
234
+ });
235
+ }
236
+ }
237
+
238
+ private setupApp() {
239
+ this.app = express();
240
+ }
241
+
242
+ private setupWatchStaticFiles() {
243
+ if (this.options.static.watch === false) {
244
+ return;
245
+ }
246
+ this.watchFiles(this.options.static.directory, this.options.static.watch);
247
+ }
248
+
249
+ private setupDevMiddleware() {
250
+ // @ts-ignored
251
+ this.middleware = rdm(this.compiler, this.options.devMiddleware);
252
+ }
253
+
254
+ private createWebsocketServer() {
255
+ if (this.options.webSocketServer !== false) {
256
+ this.webSocketServer = createWebsocketServer(this);
257
+ }
258
+ }
259
+
260
+ private setupMiddlewares() {
261
+ const options = this.options;
262
+ const middlewares: Middleware[] = [];
263
+ middlewares.push({
264
+ name: "rdm",
265
+ middleware: this.middleware
266
+ });
267
+
268
+ if (this.compiler.options.experiments.lazyCompilation) {
269
+ middlewares.push({
270
+ middleware: (req, res, next) => {
271
+ if (req.url.indexOf("/lazy-compilation-web/") > -1) {
272
+ const path = req.url.replace("/lazy-compilation-web/", "");
273
+ if (fs.existsSync(path)) {
274
+ this.compiler.rebuild([path], (error, stats) => {
275
+ if (error) {
276
+ throw error;
277
+ }
278
+ res.write("");
279
+ res.end();
280
+ console.log("lazy compiler success");
281
+ });
282
+ }
283
+ }
284
+ }
285
+ });
286
+ }
287
+
288
+ // Todo Add options
289
+ const connectHistoryApiFallback = require("connect-history-api-fallback");
290
+ middlewares.push({
291
+ name: "[connect-history-api-fallback]",
292
+ middleware: connectHistoryApiFallback({
293
+ verbose: true,
294
+ logger: console.log.bind(console)
295
+ })
296
+ });
297
+ /**
298
+ * supports three kinds of proxy configuration
299
+ * {context: 'xxxx', target: 'yyy}
300
+ * {['xxx']: { target: 'yyy}}
301
+ * [{context: 'xxx',target:'yyy'}, {context: 'aaa', target: 'zzzz'}]
302
+ */
303
+ if (typeof options.proxy !== "undefined") {
304
+ const { createProxyMiddleware } = require("http-proxy-middleware");
305
+ function getProxyMiddleware(proxyConfig) {
306
+ if (proxyConfig.target) {
307
+ const context = proxyConfig.context || proxyConfig.path;
308
+ return createProxyMiddleware(context, proxyConfig);
309
+ }
310
+ if (proxyConfig.router) {
311
+ return createProxyMiddleware(proxyConfig);
312
+ }
313
+ }
314
+ if (!Array.isArray(options.proxy)) {
315
+ if (
316
+ Object.prototype.hasOwnProperty.call(options.proxy, "target") ||
317
+ Object.prototype.hasOwnProperty.call(options.proxy, "router")
318
+ ) {
319
+ options.proxy = [options.proxy];
320
+ } else {
321
+ options.proxy = Object.keys(options.proxy).map(context => {
322
+ let proxyOptions;
323
+ // For backwards compatibility reasons.
324
+ const correctedContext = context
325
+ .replace(/^\*$/, "**")
326
+ .replace(/\/\*$/, "");
327
+
328
+ if (
329
+ typeof (/** @type {ProxyConfigMap} */ options.proxy[context]) ===
330
+ "string"
331
+ ) {
332
+ proxyOptions = {
333
+ context: correctedContext,
334
+ target:
335
+ /** @type {ProxyConfigMap} */
336
+ options.proxy[context]
337
+ };
338
+ } else {
339
+ proxyOptions = {
340
+ // @ts-ignore
341
+ .../** @type {ProxyConfigMap} */ options.proxy[context]
342
+ };
343
+ proxyOptions.context = correctedContext;
344
+ }
345
+
346
+ return proxyOptions;
347
+ });
348
+ }
349
+ }
350
+ options.proxy.forEach(proxyConfig => {
351
+ const handler = async (req, res, next) => {
352
+ let proxyMiddleware = getProxyMiddleware(proxyConfig);
353
+ const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
354
+ const bypassUrl = isByPassFuncDefined
355
+ ? await proxyConfig.bypass(req, res, proxyConfig)
356
+ : null;
357
+ if (typeof bypassUrl === "boolean") {
358
+ req.url = null;
359
+ next();
360
+ } else if (typeof bypassUrl === "string") {
361
+ req.url = bypassUrl;
362
+ } else if (proxyMiddleware) {
363
+ return proxyMiddleware(req, res, next);
364
+ } else {
365
+ next();
366
+ }
367
+ };
368
+ middlewares.push({
369
+ name: "http-proxy-middleware",
370
+ middleware: handler
371
+ });
372
+ middlewares.push({
373
+ name: "http-proxy-middleware-error-handler",
374
+ middleware: (error, req, res, next) => handler(req, res, next)
375
+ });
376
+ });
377
+ }
378
+ middlewares.push({
379
+ name: "express-static",
380
+ path: this.compiler.options.output.publicPath ?? "/",
381
+ middleware: express.static(this.options.static.directory)
382
+ });
383
+
384
+ middlewares.forEach(m => {
385
+ if (m.path) {
386
+ this.app.use(m.path, m.middleware);
387
+ } else {
388
+ this.app.use(m.middleware);
389
+ }
390
+ });
391
+ }
392
+
393
+ private createServer() {
394
+ this.server = http.createServer(this.app);
395
+ }
396
+
397
+ private setupHooks() {
398
+ this.compiler.hooks.done.tap("dev-server", stats => {
399
+ // send Message
400
+ if (this.webSocketServer) {
401
+ this.sendMessage(this.webSocketServer.clients, "ok"); // TODO: send hash
402
+ }
403
+ });
404
+ }
405
+ }
package/src/ws.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { RspackDevServer } from "./server";
2
+ import WebSocket from "ws";
3
+ import WebpackWsServer from "webpack-dev-server/lib/servers/WebsocketServer";
4
+
5
+ export type ClientConnection = WebSocket & { isAlive?: boolean };
6
+
7
+ export interface WebSocketServer {
8
+ heartbeatInterval: number;
9
+ implementation: WebSocket.Server<WebSocket.WebSocket>;
10
+ server: RspackDevServer;
11
+ clients: ClientConnection[];
12
+ }
13
+
14
+ export function createWebsocketServer(
15
+ server: RspackDevServer
16
+ ): WebSocketServer {
17
+ return new WebpackWsServer(server);
18
+ }