@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.
- package/CHANGELOG.md +90 -0
- package/README.md +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +55 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +28 -0
- package/dist/logger.js.map +1 -0
- package/dist/reload.d.ts +9 -0
- package/dist/reload.d.ts.map +1 -0
- package/dist/reload.js +23 -0
- package/dist/reload.js.map +1 -0
- package/dist/server.d.ts +55 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +324 -0
- package/dist/server.js.map +1 -0
- package/dist/ws.d.ts +13 -0
- package/dist/ws.d.ts.map +1 -0
- package/dist/ws.js +12 -0
- package/dist/ws.js.map +1 -0
- package/jest.config.js +7 -0
- package/package.json +36 -0
- package/src/config.ts +72 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +30 -0
- package/src/reload.ts +31 -0
- package/src/server.ts +405 -0
- package/src/ws.ts +18 -0
- package/tests/__snapshots__/normalizeOptions.test.ts.snap +83 -0
- package/tests/normalizeOptions.test.ts +73 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# rspack-dev-server
|
|
2
|
+
|
|
3
|
+
## 0.0.0-01dbf86423-20221210100716
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3701a8bf58: fix less resolve bug
|
|
8
|
+
- Updated dependencies [3701a8bf58]
|
|
9
|
+
- @rspack/core@0.0.0-01dbf86423-20221210100716
|
|
10
|
+
- @rspack/dev-client@0.0.0-01dbf86423-20221210100716
|
|
11
|
+
- @rspack/dev-middleware@0.0.0-01dbf86423-20221210100716
|
|
12
|
+
- @rspack/dev-server@0.0.0-01dbf86423-20221210100716
|
|
13
|
+
|
|
14
|
+
## 0.0.12
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- @rspack/core@0.0.12
|
|
19
|
+
- @rspack/dev-client@0.0.12
|
|
20
|
+
- @rspack/dev-middleware@0.0.12
|
|
21
|
+
- @rspack/dev-server@0.0.12
|
|
22
|
+
|
|
23
|
+
## 0.0.11
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [2eca9ade]
|
|
28
|
+
- @rspack/core@0.0.11
|
|
29
|
+
- @rspack/dev-middleware@0.0.11
|
|
30
|
+
- @rspack/dev-server@0.0.11
|
|
31
|
+
- @rspack/dev-client@0.0.11
|
|
32
|
+
|
|
33
|
+
## 0.0.10
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [062e692d]
|
|
38
|
+
- @rspack/core@0.0.10
|
|
39
|
+
- @rspack/dev-middleware@0.0.10
|
|
40
|
+
- @rspack/dev-server@0.0.10
|
|
41
|
+
- @rspack/dev-client@0.0.10
|
|
42
|
+
|
|
43
|
+
## 0.0.9
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- @rspack/core@0.0.9
|
|
48
|
+
- @rspack/dev-middleware@0.0.9
|
|
49
|
+
- @rspack/dev-server@0.0.9
|
|
50
|
+
- @rspack/dev-client@0.0.9
|
|
51
|
+
|
|
52
|
+
## 0.0.8
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- 589b99bb: bump to 0.0.8
|
|
57
|
+
- Updated dependencies [589b99bb]
|
|
58
|
+
- @rspack/core@0.0.8
|
|
59
|
+
- @rspack/dev-client@0.0.8
|
|
60
|
+
- @rspack/dev-middleware@0.0.8
|
|
61
|
+
- @rspack/dev-server@0.0.8
|
|
62
|
+
|
|
63
|
+
## 0.0.6
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- e6d0926a: unify version
|
|
68
|
+
- Updated dependencies [e6d0926a]
|
|
69
|
+
- @rspack/core@0.0.6
|
|
70
|
+
- @rspack/dev-server@0.0.6
|
|
71
|
+
- @rspack/dev-middleware@0.0.6
|
|
72
|
+
- @rspack/dev-client@0.0.6
|
|
73
|
+
|
|
74
|
+
## 0.0.4
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- d466288: add process_assets hook
|
|
79
|
+
|
|
80
|
+
## 0.0.3
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- 536f6f70: fix broken lib
|
|
85
|
+
|
|
86
|
+
## 0.0.2
|
|
87
|
+
|
|
88
|
+
### Patch Changes
|
|
89
|
+
|
|
90
|
+
- bd57e818: first release
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# rspack-dev-server
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Dev, WebSocketServerOptions, RspackOptionsNormalized } from "@rspack/core";
|
|
2
|
+
import type { WatchOptions } from "chokidar";
|
|
3
|
+
import { ProxyOptions } from "@rspack/core/src/config/devServer";
|
|
4
|
+
export interface ResolvedDev {
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
static: {
|
|
8
|
+
directory: string;
|
|
9
|
+
watch: false | WatchOptions;
|
|
10
|
+
};
|
|
11
|
+
devMiddleware: {};
|
|
12
|
+
hot: boolean;
|
|
13
|
+
open: boolean;
|
|
14
|
+
liveReload: boolean;
|
|
15
|
+
webSocketServer: false | WebSocketServerOptions;
|
|
16
|
+
proxy: ProxyOptions;
|
|
17
|
+
}
|
|
18
|
+
export declare function resolveDevOptions(devConfig: Dev, compilerOptions: RspackOptionsNormalized): ResolvedDev;
|
|
19
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,sBAAsB,EACtB,uBAAuB,EACvB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QACP,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,KAAK,GAAG,YAAY,CAAC;KAC5B,CAAC;IACF,aAAa,EAAE,EAAE,CAAC;IAClB,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,KAAK,GAAG,sBAAsB,CAAC;IAChD,KAAK,EAAE,YAAY,CAAC;CACpB;AAED,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,GAAG,EACd,eAAe,EAAE,uBAAuB,GACtC,WAAW,CA2Cb"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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.resolveDevOptions = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const core_1 = require("@rspack/core");
|
|
9
|
+
function resolveDevOptions(devConfig, compilerOptions) {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11
|
+
const open = true;
|
|
12
|
+
const proxy = devConfig.proxy;
|
|
13
|
+
const hot = (_a = devConfig.hot) !== null && _a !== void 0 ? _a : true;
|
|
14
|
+
// --- static
|
|
15
|
+
const directory = (_c = (_b = devConfig.static) === null || _b === void 0 ? void 0 : _b.directory) !== null && _c !== void 0 ? _c : path_1.default.resolve(compilerOptions.context, compilerOptions.output.path);
|
|
16
|
+
let watch = {};
|
|
17
|
+
if (((_d = devConfig.static) === null || _d === void 0 ? void 0 : _d.watch) === false) {
|
|
18
|
+
watch = false;
|
|
19
|
+
}
|
|
20
|
+
else if (((_e = devConfig.static) === null || _e === void 0 ? void 0 : _e.watch) === true) {
|
|
21
|
+
watch = (0, core_1.resolveWatchOption)({});
|
|
22
|
+
}
|
|
23
|
+
else if ((_f = devConfig.static) === null || _f === void 0 ? void 0 : _f.watch) {
|
|
24
|
+
watch = (_g = devConfig.static) === null || _g === void 0 ? void 0 : _g.watch;
|
|
25
|
+
}
|
|
26
|
+
// ---
|
|
27
|
+
const devMiddleware = (_h = devConfig.devMiddleware) !== null && _h !== void 0 ? _h : {};
|
|
28
|
+
const liveReload = (_j = devConfig.liveReload) !== null && _j !== void 0 ? _j : true;
|
|
29
|
+
let webSocketServer = {};
|
|
30
|
+
if (devConfig.webSocketServer === false) {
|
|
31
|
+
webSocketServer = false;
|
|
32
|
+
}
|
|
33
|
+
else if (devConfig.webSocketServer === true) {
|
|
34
|
+
webSocketServer = {};
|
|
35
|
+
}
|
|
36
|
+
else if (devConfig.webSocketServer) {
|
|
37
|
+
webSocketServer = devConfig.webSocketServer;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
host: devConfig.host,
|
|
41
|
+
port: devConfig.port ? Number(devConfig.port) : undefined,
|
|
42
|
+
static: {
|
|
43
|
+
directory,
|
|
44
|
+
watch
|
|
45
|
+
},
|
|
46
|
+
devMiddleware,
|
|
47
|
+
open,
|
|
48
|
+
hot,
|
|
49
|
+
liveReload,
|
|
50
|
+
webSocketServer,
|
|
51
|
+
proxy
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.resolveDevOptions = resolveDevOptions;
|
|
55
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;AAMA,gDAAwB;AACxB,uCAAkD;AAkBlD,SAAgB,iBAAiB,CAChC,SAAc,EACd,eAAwC;;IAExC,MAAM,IAAI,GAAG,IAAI,CAAC;IAClB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;IAC9B,MAAM,GAAG,GAAG,MAAA,SAAS,CAAC,GAAG,mCAAI,IAAI,CAAC;IAClC,aAAa;IACb,MAAM,SAAS,GACd,MAAA,MAAA,SAAS,CAAC,MAAM,0CAAE,SAAS,mCAC3B,cAAI,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpE,IAAI,KAAK,GAAyB,EAAE,CAAC;IACrC,IAAI,CAAA,MAAA,SAAS,CAAC,MAAM,0CAAE,KAAK,MAAK,KAAK,EAAE;QACtC,KAAK,GAAG,KAAK,CAAC;KACd;SAAM,IAAI,CAAA,MAAA,SAAS,CAAC,MAAM,0CAAE,KAAK,MAAK,IAAI,EAAE;QAC5C,KAAK,GAAG,IAAA,yBAAkB,EAAC,EAAE,CAAC,CAAC;KAC/B;SAAM,IAAI,MAAA,SAAS,CAAC,MAAM,0CAAE,KAAK,EAAE;QACnC,KAAK,GAAG,MAAA,SAAS,CAAC,MAAM,0CAAE,KAAK,CAAC;KAChC;IACD,MAAM;IACN,MAAM,aAAa,GAAG,MAAA,SAAS,CAAC,aAAa,mCAAI,EAAE,CAAC;IACpD,MAAM,UAAU,GAAG,MAAA,SAAS,CAAC,UAAU,mCAAI,IAAI,CAAC;IAEhD,IAAI,eAAe,GAAmC,EAAE,CAAC;IACzD,IAAI,SAAS,CAAC,eAAe,KAAK,KAAK,EAAE;QACxC,eAAe,GAAG,KAAK,CAAC;KACxB;SAAM,IAAI,SAAS,CAAC,eAAe,KAAK,IAAI,EAAE;QAC9C,eAAe,GAAG,EAAE,CAAC;KACrB;SAAM,IAAI,SAAS,CAAC,eAAe,EAAE;QACrC,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC;KAC5C;IAED,OAAO;QACN,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QACzD,MAAM,EAAE;YACP,SAAS;YACT,KAAK;SACL;QACD,aAAa;QACb,IAAI;QACJ,GAAG;QACH,UAAU;QACV,eAAe;QACf,KAAK;KACL,CAAC;AACH,CAAC;AA9CD,8CA8CC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RspackDevServer = void 0;
|
|
4
|
+
var server_1 = require("./server");
|
|
5
|
+
Object.defineProperty(exports, "RspackDevServer", { enumerable: true, get: function () { return server_1.RspackDevServer; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA2C;AAAlC,yGAAA,eAAe,OAAA"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACtB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC3B;AAUD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAejD"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLogger = void 0;
|
|
4
|
+
const COLOR = {
|
|
5
|
+
RESET: "\x1b[0m",
|
|
6
|
+
//
|
|
7
|
+
RED: "\x1b[31m",
|
|
8
|
+
GREEN: "\x1b[32m",
|
|
9
|
+
YELLOW: "\x1b[33m"
|
|
10
|
+
};
|
|
11
|
+
function createLogger(name) {
|
|
12
|
+
if (!name.length) {
|
|
13
|
+
throw Error();
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
error(...msgs) {
|
|
17
|
+
console.log("[", name, "]:", COLOR.RED, msgs, COLOR.RESET);
|
|
18
|
+
},
|
|
19
|
+
warn(...msgs) {
|
|
20
|
+
console.log("[", name, "]:", COLOR.YELLOW, msgs, COLOR.RESET);
|
|
21
|
+
},
|
|
22
|
+
info(...msgs) {
|
|
23
|
+
console.log("[", name, "]:", COLOR.GREEN, msgs, COLOR.RESET);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.createLogger = createLogger;
|
|
28
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAMA,MAAM,KAAK,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,EAAE;IACF,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;CAClB,CAAC;AAEF,SAAgB,YAAY,CAAC,IAAY;IACxC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;QACjB,MAAM,KAAK,EAAE,CAAC;KACd;IACD,OAAO;QACN,KAAK,CAAC,GAAG,IAAW;YACnB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,GAAG,IAAW;YAClB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,CAAC,GAAG,IAAW;YAClB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC9D,CAAC;KACD,CAAC;AACH,CAAC;AAfD,oCAeC"}
|
package/dist/reload.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RspackOptionsNormalized } from "@rspack/core";
|
|
2
|
+
interface Status {
|
|
3
|
+
isUnloading: boolean;
|
|
4
|
+
currentHash: string;
|
|
5
|
+
previousHash: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function reloadApp({ liveReload, hot }: RspackOptionsNormalized["devServer"], status: Status): void;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=reload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reload.d.ts","sourceRoot":"","sources":["../src/reload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAE5D,UAAU,MAAM;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,wBAAgB,SAAS,CACxB,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,uBAAuB,CAAC,WAAW,CAAC,EACzD,MAAM,EAAE,MAAM,QAoBd"}
|
package/dist/reload.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reloadApp = void 0;
|
|
4
|
+
function reloadApp({ liveReload, hot }, status) {
|
|
5
|
+
if (status.isUnloading) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
function applyReload(rootWindow, intervalId) {
|
|
9
|
+
clearInterval(intervalId);
|
|
10
|
+
console.log("App update, Reloading...");
|
|
11
|
+
rootWindow.location.reload();
|
|
12
|
+
}
|
|
13
|
+
if (liveReload) {
|
|
14
|
+
let rootWindow = self;
|
|
15
|
+
const intervalId = self.setInterval(() => {
|
|
16
|
+
if (rootWindow.location.protocol !== "about:") {
|
|
17
|
+
applyReload(rootWindow, intervalId);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.reloadApp = reloadApp;
|
|
23
|
+
//# sourceMappingURL=reload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reload.js","sourceRoot":"","sources":["../src/reload.ts"],"names":[],"mappings":";;;AAQA,SAAgB,SAAS,CACxB,EAAE,UAAU,EAAE,GAAG,EAAwC,EACzD,MAAc;IAEd,IAAI,MAAM,CAAC,WAAW,EAAE;QACvB,OAAO;KACP;IAED,SAAS,WAAW,CAAC,UAAkB,EAAE,UAAkB;QAC1D,aAAa,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QACxC,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,IAAI,UAAU,EAAE;QACf,IAAI,UAAU,GAAG,IAAI,CAAC;QACtB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE;YACxC,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBAC9C,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;aACpC;QACF,CAAC,CAAC,CAAC;KACH;AACF,CAAC;AAtBD,8BAsBC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { Compiler, Dev } from "@rspack/core";
|
|
4
|
+
import type { Logger } from "./logger";
|
|
5
|
+
import type { Socket } from "net";
|
|
6
|
+
import type { FSWatcher, WatchOptions } from "chokidar";
|
|
7
|
+
import type { WebSocketServer, ClientConnection } from "./ws";
|
|
8
|
+
import type { Application } from "express";
|
|
9
|
+
import type { Server } from "http";
|
|
10
|
+
import type { ResolvedDev } from "./config";
|
|
11
|
+
declare type Host = "local-ip" | "local-ipv4" | "local-ipv6" | string;
|
|
12
|
+
declare type Port = number | string | "auto";
|
|
13
|
+
export declare class RspackDevServer {
|
|
14
|
+
compiler: Compiler;
|
|
15
|
+
options: ResolvedDev;
|
|
16
|
+
logger: Logger;
|
|
17
|
+
staticWatchers: FSWatcher[];
|
|
18
|
+
sockets: Socket[];
|
|
19
|
+
app: Application;
|
|
20
|
+
server: Server;
|
|
21
|
+
private listeners;
|
|
22
|
+
private currentHash;
|
|
23
|
+
private middleware;
|
|
24
|
+
webSocketServer: WebSocketServer | undefined;
|
|
25
|
+
constructor(compiler: Compiler);
|
|
26
|
+
normalizeOptions(dev?: Dev): ResolvedDev;
|
|
27
|
+
rewriteCompilerOptions(): void;
|
|
28
|
+
addAdditionEntires(): void;
|
|
29
|
+
static isAbsoluteURL(URL: string): boolean;
|
|
30
|
+
static findIp(gateway: string): string | undefined;
|
|
31
|
+
static internalIP(family: "v6" | "v4"): Promise<string | undefined>;
|
|
32
|
+
static internalIPSync(family: "v6" | "v4"): Promise<string | undefined>;
|
|
33
|
+
static getHostname(hostname?: Host): Promise<string>;
|
|
34
|
+
static getFreePort(port: Port, host: string): Promise<string | number>;
|
|
35
|
+
static findCacheDir(): string;
|
|
36
|
+
private getCompilerOptions;
|
|
37
|
+
sendMessage(clients: ClientConnection[], type: string, data?: any, params?: any): void;
|
|
38
|
+
watchFiles(watchPath: string | string[], watchOptions?: WatchOptions): void;
|
|
39
|
+
invalidate(callback?: () => void): void;
|
|
40
|
+
start(): Promise<void>;
|
|
41
|
+
startCallback(callback?: (err?: Error) => void): void;
|
|
42
|
+
stopCallback(callback?: (err?: Error) => void): void;
|
|
43
|
+
listen(port: Port, hostname: string, fn: (err?: Error) => void): void;
|
|
44
|
+
close(callback?: (err?: Error) => void): void;
|
|
45
|
+
stop(): Promise<void>;
|
|
46
|
+
private setupApp;
|
|
47
|
+
private setupWatchStaticFiles;
|
|
48
|
+
private setupDevMiddleware;
|
|
49
|
+
private createWebsocketServer;
|
|
50
|
+
private setupMiddlewares;
|
|
51
|
+
private createServer;
|
|
52
|
+
private setupHooks;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"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"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
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.RspackDevServer = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const chokidar_1 = __importDefault(require("chokidar"));
|
|
9
|
+
const http_1 = __importDefault(require("http"));
|
|
10
|
+
const logger_1 = require("./logger");
|
|
11
|
+
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
12
|
+
const express_1 = __importDefault(require("express"));
|
|
13
|
+
const dev_middleware_1 = __importDefault(require("@rspack/dev-middleware"));
|
|
14
|
+
const ws_1 = require("./ws");
|
|
15
|
+
const config_1 = require("./config");
|
|
16
|
+
// copy from webpack-dev-server
|
|
17
|
+
class RspackDevServer {
|
|
18
|
+
constructor(compiler) {
|
|
19
|
+
this.compiler = compiler;
|
|
20
|
+
this.logger = (0, logger_1.createLogger)("rspack-dev-server");
|
|
21
|
+
this.staticWatchers = [];
|
|
22
|
+
this.listeners = [];
|
|
23
|
+
this.sockets = [];
|
|
24
|
+
this.currentHash = "";
|
|
25
|
+
this.options = this.normalizeOptions(compiler.options.devServer);
|
|
26
|
+
this.rewriteCompilerOptions();
|
|
27
|
+
this.addAdditionEntires();
|
|
28
|
+
}
|
|
29
|
+
normalizeOptions(dev = {}) {
|
|
30
|
+
return (0, config_1.resolveDevOptions)(dev, this.compiler.options);
|
|
31
|
+
}
|
|
32
|
+
rewriteCompilerOptions() {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
if (!this.compiler.options.builtins.react) {
|
|
35
|
+
this.compiler.options.builtins.react = {};
|
|
36
|
+
}
|
|
37
|
+
this.compiler.options.builtins.react.development =
|
|
38
|
+
(_a = this.compiler.options.builtins.react.development) !== null && _a !== void 0 ? _a : true;
|
|
39
|
+
if (this.options.hot) {
|
|
40
|
+
this.compiler.options.builtins.react.refresh =
|
|
41
|
+
(_b = this.compiler.options.builtins.react.refresh) !== null && _b !== void 0 ? _b : true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
addAdditionEntires() {
|
|
45
|
+
var _a;
|
|
46
|
+
const entries = [];
|
|
47
|
+
if (this.options.hot) {
|
|
48
|
+
const hotUpdateEntryPath = require.resolve("@rspack/dev-client/devServer");
|
|
49
|
+
entries.push(hotUpdateEntryPath);
|
|
50
|
+
if ((_a = this.compiler.options.builtins.react) === null || _a === void 0 ? void 0 : _a.refresh) {
|
|
51
|
+
const reactRefreshEntryPath = require.resolve("@rspack/dev-client/react-refresh");
|
|
52
|
+
entries.push(reactRefreshEntryPath);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const devClientEntryPath = require.resolve("@rspack/dev-client");
|
|
56
|
+
entries.push(devClientEntryPath);
|
|
57
|
+
for (const key in this.compiler.options.entry) {
|
|
58
|
+
this.compiler.options.entry[key].import.unshift(...entries);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static isAbsoluteURL(URL) {
|
|
62
|
+
return webpack_dev_server_1.default.isAbsoluteURL(URL);
|
|
63
|
+
}
|
|
64
|
+
static findIp(gateway) {
|
|
65
|
+
return webpack_dev_server_1.default.findIp(gateway);
|
|
66
|
+
}
|
|
67
|
+
static async internalIP(family) {
|
|
68
|
+
return webpack_dev_server_1.default.internalIP(family);
|
|
69
|
+
}
|
|
70
|
+
static async internalIPSync(family) {
|
|
71
|
+
return webpack_dev_server_1.default.internalIPSync(family);
|
|
72
|
+
}
|
|
73
|
+
static async getHostname(hostname) {
|
|
74
|
+
return webpack_dev_server_1.default.getHostname(hostname);
|
|
75
|
+
}
|
|
76
|
+
static async getFreePort(port, host) {
|
|
77
|
+
return webpack_dev_server_1.default.getFreePort(port, host);
|
|
78
|
+
}
|
|
79
|
+
static findCacheDir() {
|
|
80
|
+
// TODO: we need remove the `webpack-dev-server` tag in WebpackDevServer;
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
getCompilerOptions() {
|
|
84
|
+
return this.compiler.options;
|
|
85
|
+
}
|
|
86
|
+
sendMessage(clients, type, data, params) {
|
|
87
|
+
for (const client of clients) {
|
|
88
|
+
if (client.readyState === 1) {
|
|
89
|
+
client.send(JSON.stringify({ type, data, params }));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
watchFiles(watchPath, watchOptions) {
|
|
94
|
+
const watcher = chokidar_1.default.watch(watchPath, watchOptions);
|
|
95
|
+
// disabling refreshing on changing the content
|
|
96
|
+
if (this.options.liveReload) {
|
|
97
|
+
// TODO: remove this after we had memory filesystem
|
|
98
|
+
if (this.options.hot) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
watcher.on("change", item => {
|
|
102
|
+
if (this.webSocketServer) {
|
|
103
|
+
this.sendMessage(this.webSocketServer.clients, "static-changed", item);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
this.staticWatchers.push(watcher);
|
|
108
|
+
}
|
|
109
|
+
invalidate(callback = () => { }) {
|
|
110
|
+
if (this.middleware) {
|
|
111
|
+
this.middleware.invalidate(callback);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async start() {
|
|
115
|
+
this.setupHooks();
|
|
116
|
+
this.setupApp();
|
|
117
|
+
this.createServer();
|
|
118
|
+
this.setupWatchStaticFiles();
|
|
119
|
+
this.createWebsocketServer();
|
|
120
|
+
this.setupDevMiddleware();
|
|
121
|
+
this.setupMiddlewares();
|
|
122
|
+
const host = await RspackDevServer.getHostname(this.options.host);
|
|
123
|
+
const port = await RspackDevServer.getFreePort(this.options.port, host);
|
|
124
|
+
await new Promise(resolve => this.server.listen({
|
|
125
|
+
port,
|
|
126
|
+
host
|
|
127
|
+
}, () => {
|
|
128
|
+
this.logger.info(`Loopback: http://localhost:${port}`);
|
|
129
|
+
let internalIPv4 = webpack_dev_server_1.default.internalIPSync("v4");
|
|
130
|
+
this.logger.info(`Your Network (IPV4) http://${internalIPv4}:${port}`);
|
|
131
|
+
resolve({});
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
startCallback(callback) {
|
|
135
|
+
throw new Error("Method not implemented.");
|
|
136
|
+
}
|
|
137
|
+
stopCallback(callback) {
|
|
138
|
+
throw new Error("Method not implemented.");
|
|
139
|
+
}
|
|
140
|
+
listen(port, hostname, fn) {
|
|
141
|
+
throw new Error("Method not implemented.");
|
|
142
|
+
}
|
|
143
|
+
close(callback) {
|
|
144
|
+
throw new Error("Method not implemented.");
|
|
145
|
+
}
|
|
146
|
+
async stop() {
|
|
147
|
+
await Promise.all(this.staticWatchers.map(watcher => watcher.close()));
|
|
148
|
+
this.middleware = null;
|
|
149
|
+
this.staticWatchers = [];
|
|
150
|
+
if (this.server) {
|
|
151
|
+
this.server.close();
|
|
152
|
+
}
|
|
153
|
+
if (this.webSocketServer) {
|
|
154
|
+
await new Promise(resolve => {
|
|
155
|
+
this.webSocketServer.implementation.close(() => {
|
|
156
|
+
resolve(void 0);
|
|
157
|
+
});
|
|
158
|
+
for (const client of this.webSocketServer.clients)
|
|
159
|
+
client.terminate();
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
setupApp() {
|
|
164
|
+
this.app = (0, express_1.default)();
|
|
165
|
+
}
|
|
166
|
+
setupWatchStaticFiles() {
|
|
167
|
+
if (this.options.static.watch === false) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.watchFiles(this.options.static.directory, this.options.static.watch);
|
|
171
|
+
}
|
|
172
|
+
setupDevMiddleware() {
|
|
173
|
+
// @ts-ignored
|
|
174
|
+
this.middleware = (0, dev_middleware_1.default)(this.compiler, this.options.devMiddleware);
|
|
175
|
+
}
|
|
176
|
+
createWebsocketServer() {
|
|
177
|
+
if (this.options.webSocketServer !== false) {
|
|
178
|
+
this.webSocketServer = (0, ws_1.createWebsocketServer)(this);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
setupMiddlewares() {
|
|
182
|
+
var _a;
|
|
183
|
+
const options = this.options;
|
|
184
|
+
const middlewares = [];
|
|
185
|
+
middlewares.push({
|
|
186
|
+
name: "rdm",
|
|
187
|
+
middleware: this.middleware
|
|
188
|
+
});
|
|
189
|
+
if (this.compiler.options.experiments.lazyCompilation) {
|
|
190
|
+
middlewares.push({
|
|
191
|
+
middleware: (req, res, next) => {
|
|
192
|
+
if (req.url.indexOf("/lazy-compilation-web/") > -1) {
|
|
193
|
+
const path = req.url.replace("/lazy-compilation-web/", "");
|
|
194
|
+
if (fs_1.default.existsSync(path)) {
|
|
195
|
+
this.compiler.rebuild([path], (error, stats) => {
|
|
196
|
+
if (error) {
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
res.write("");
|
|
200
|
+
res.end();
|
|
201
|
+
console.log("lazy compiler success");
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
// Todo Add options
|
|
209
|
+
const connectHistoryApiFallback = require("connect-history-api-fallback");
|
|
210
|
+
middlewares.push({
|
|
211
|
+
name: "[connect-history-api-fallback]",
|
|
212
|
+
middleware: connectHistoryApiFallback({
|
|
213
|
+
verbose: true,
|
|
214
|
+
logger: console.log.bind(console)
|
|
215
|
+
})
|
|
216
|
+
});
|
|
217
|
+
/**
|
|
218
|
+
* supports three kinds of proxy configuration
|
|
219
|
+
* {context: 'xxxx', target: 'yyy}
|
|
220
|
+
* {['xxx']: { target: 'yyy}}
|
|
221
|
+
* [{context: 'xxx',target:'yyy'}, {context: 'aaa', target: 'zzzz'}]
|
|
222
|
+
*/
|
|
223
|
+
if (typeof options.proxy !== "undefined") {
|
|
224
|
+
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
225
|
+
function getProxyMiddleware(proxyConfig) {
|
|
226
|
+
if (proxyConfig.target) {
|
|
227
|
+
const context = proxyConfig.context || proxyConfig.path;
|
|
228
|
+
return createProxyMiddleware(context, proxyConfig);
|
|
229
|
+
}
|
|
230
|
+
if (proxyConfig.router) {
|
|
231
|
+
return createProxyMiddleware(proxyConfig);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!Array.isArray(options.proxy)) {
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(options.proxy, "target") ||
|
|
236
|
+
Object.prototype.hasOwnProperty.call(options.proxy, "router")) {
|
|
237
|
+
options.proxy = [options.proxy];
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
options.proxy = Object.keys(options.proxy).map(context => {
|
|
241
|
+
let proxyOptions;
|
|
242
|
+
// For backwards compatibility reasons.
|
|
243
|
+
const correctedContext = context
|
|
244
|
+
.replace(/^\*$/, "**")
|
|
245
|
+
.replace(/\/\*$/, "");
|
|
246
|
+
if (typeof ( /** @type {ProxyConfigMap} */options.proxy[context]) ===
|
|
247
|
+
"string") {
|
|
248
|
+
proxyOptions = {
|
|
249
|
+
context: correctedContext,
|
|
250
|
+
target:
|
|
251
|
+
/** @type {ProxyConfigMap} */
|
|
252
|
+
options.proxy[context]
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
proxyOptions = {
|
|
257
|
+
// @ts-ignore
|
|
258
|
+
... /** @type {ProxyConfigMap} */options.proxy[context]
|
|
259
|
+
};
|
|
260
|
+
proxyOptions.context = correctedContext;
|
|
261
|
+
}
|
|
262
|
+
return proxyOptions;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
options.proxy.forEach(proxyConfig => {
|
|
267
|
+
const handler = async (req, res, next) => {
|
|
268
|
+
let proxyMiddleware = getProxyMiddleware(proxyConfig);
|
|
269
|
+
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
|
|
270
|
+
const bypassUrl = isByPassFuncDefined
|
|
271
|
+
? await proxyConfig.bypass(req, res, proxyConfig)
|
|
272
|
+
: null;
|
|
273
|
+
if (typeof bypassUrl === "boolean") {
|
|
274
|
+
req.url = null;
|
|
275
|
+
next();
|
|
276
|
+
}
|
|
277
|
+
else if (typeof bypassUrl === "string") {
|
|
278
|
+
req.url = bypassUrl;
|
|
279
|
+
}
|
|
280
|
+
else if (proxyMiddleware) {
|
|
281
|
+
return proxyMiddleware(req, res, next);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
next();
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
middlewares.push({
|
|
288
|
+
name: "http-proxy-middleware",
|
|
289
|
+
middleware: handler
|
|
290
|
+
});
|
|
291
|
+
middlewares.push({
|
|
292
|
+
name: "http-proxy-middleware-error-handler",
|
|
293
|
+
middleware: (error, req, res, next) => handler(req, res, next)
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
middlewares.push({
|
|
298
|
+
name: "express-static",
|
|
299
|
+
path: (_a = this.compiler.options.output.publicPath) !== null && _a !== void 0 ? _a : "/",
|
|
300
|
+
middleware: express_1.default.static(this.options.static.directory)
|
|
301
|
+
});
|
|
302
|
+
middlewares.forEach(m => {
|
|
303
|
+
if (m.path) {
|
|
304
|
+
this.app.use(m.path, m.middleware);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
this.app.use(m.middleware);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
createServer() {
|
|
312
|
+
this.server = http_1.default.createServer(this.app);
|
|
313
|
+
}
|
|
314
|
+
setupHooks() {
|
|
315
|
+
this.compiler.hooks.done.tap("dev-server", stats => {
|
|
316
|
+
// send Message
|
|
317
|
+
if (this.webSocketServer) {
|
|
318
|
+
this.sendMessage(this.webSocketServer.clients, "ok"); // TODO: send hash
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
exports.RspackDevServer = RspackDevServer;
|
|
324
|
+
//# sourceMappingURL=server.js.map
|