@rspack/dev-server 1.2.1 → 2.0.0-beta.1
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/README.md +16 -17
- package/client/index.js +6 -6
- package/client/overlay.js +4 -4
- package/client/utils/ansiHTML.js +9 -9
- package/client/utils/log.js +1 -1
- package/dist/config.d.ts +1 -3
- package/dist/getPort.js +18 -8
- package/dist/server.d.ts +5 -16
- package/dist/server.js +137 -388
- package/dist/types.d.ts +10 -27
- package/package.json +39 -65
- package/client/clients/SockJSClient.js +0 -34
- package/client/modules/sockjs-client/index.js +0 -4506
- package/dist/options.json +0 -1034
- package/dist/servers/SockJSServer.d.ts +0 -10
- package/dist/servers/SockJSServer.js +0 -110
package/README.md
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
Use Rspack with a development server that provides live reloading. This should be used for development only.
|
|
11
11
|
|
|
12
|
-
>
|
|
12
|
+
> [!NOTE]
|
|
13
|
+
> The `main` branch is under active development for 2.0.
|
|
14
|
+
> The stable `1.x` releases are maintained in the [v1.x](https://github.com/rstackjs/rspack-dev-server/tree/v1.x) branch.
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
|
@@ -17,16 +19,16 @@ First of all, install `@rspack/dev-server` and `@rspack/core` by your favorite p
|
|
|
17
19
|
|
|
18
20
|
```bash
|
|
19
21
|
# npm
|
|
20
|
-
$ npm install @rspack/dev-server @rspack/core
|
|
22
|
+
$ npm install -D @rspack/dev-server @rspack/core
|
|
21
23
|
|
|
22
24
|
# yarn
|
|
23
|
-
$ yarn add @rspack/dev-server @rspack/core
|
|
25
|
+
$ yarn add -D @rspack/dev-server @rspack/core
|
|
24
26
|
|
|
25
27
|
# pnpm
|
|
26
|
-
$ pnpm add @rspack/dev-server @rspack/core
|
|
28
|
+
$ pnpm add -D @rspack/dev-server @rspack/core
|
|
27
29
|
|
|
28
30
|
# bun
|
|
29
|
-
$ bun add @rspack/dev-server @rspack/core
|
|
31
|
+
$ bun add -D @rspack/dev-server @rspack/core
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
## Usage
|
|
@@ -41,16 +43,16 @@ You can install it in your project by:
|
|
|
41
43
|
|
|
42
44
|
```bash
|
|
43
45
|
# npm
|
|
44
|
-
$ npm install @rspack/cli
|
|
46
|
+
$ npm install -D @rspack/cli
|
|
45
47
|
|
|
46
48
|
# yarn
|
|
47
|
-
$ yarn add @rspack/cli
|
|
49
|
+
$ yarn add -D @rspack/cli
|
|
48
50
|
|
|
49
51
|
# pnpm
|
|
50
|
-
$ pnpm add @rspack/cli
|
|
52
|
+
$ pnpm add -D @rspack/cli
|
|
51
53
|
|
|
52
54
|
# bun
|
|
53
|
-
$ bun add @rspack/cli
|
|
55
|
+
$ bun add -D @rspack/cli
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
And then start the development server by:
|
|
@@ -70,7 +72,6 @@ While starting the development server, you can specify the configuration by the
|
|
|
70
72
|
```js
|
|
71
73
|
// rspack.config.mjs
|
|
72
74
|
export default {
|
|
73
|
-
// ...
|
|
74
75
|
devServer: {
|
|
75
76
|
// the configuration of the development server
|
|
76
77
|
port: 8080,
|
|
@@ -78,7 +79,7 @@ export default {
|
|
|
78
79
|
};
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
> See [
|
|
82
|
+
> See [Rspack - devServer](https://rspack.rs/config/dev-server) for all configuration options.
|
|
82
83
|
|
|
83
84
|
### With the API
|
|
84
85
|
|
|
@@ -86,12 +87,12 @@ While it's recommended to run `@rspack/dev-server` via the CLI, you may also cho
|
|
|
86
87
|
|
|
87
88
|
```js
|
|
88
89
|
import { RspackDevServer } from '@rspack/dev-server';
|
|
89
|
-
import rspack from '@rspack/core';
|
|
90
|
-
import
|
|
90
|
+
import { rspack } from '@rspack/core';
|
|
91
|
+
import config from './rspack.config.mjs';
|
|
91
92
|
|
|
92
|
-
const compiler = rspack(
|
|
93
|
+
const compiler = rspack(config);
|
|
93
94
|
const devServerOptions = {
|
|
94
|
-
...
|
|
95
|
+
...config.devServer,
|
|
95
96
|
// override
|
|
96
97
|
port: 8888,
|
|
97
98
|
};
|
|
@@ -103,8 +104,6 @@ server.startCallback(() => {
|
|
|
103
104
|
});
|
|
104
105
|
```
|
|
105
106
|
|
|
106
|
-
> Cause `@rspack/dev-server` is based on `webpack-dev-server@5`, you can see the [webpack-dev-server API](https://webpack.js.org/api/webpack-dev-server/) for more methods of the server instance.
|
|
107
|
-
|
|
108
107
|
## Credits
|
|
109
108
|
|
|
110
109
|
This plugin is forked from [webpack-dev-server](https://github.com/webpack/webpack-dev-server), and is used to smooth out some differences between rspack and webpack, while also providing rspack-specific new features.
|
package/client/index.js
CHANGED
|
@@ -19,10 +19,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
19
19
|
return __assign.apply(this, arguments);
|
|
20
20
|
};
|
|
21
21
|
// @ts-expect-error: No type definitions available for '@rspack/core/hot/emitter.js'
|
|
22
|
-
import hotEmitter from '@rspack/core/hot/emitter.js';
|
|
22
|
+
import { emitter as hotEmitter } from '@rspack/core/hot/emitter.js';
|
|
23
23
|
/* Rspack dev server runtime client */
|
|
24
24
|
// @ts-expect-error: No type definitions available for '@rspack/core/hot/log.js'
|
|
25
|
-
import webpackHotLog from '@rspack/core/hot/log.js';
|
|
25
|
+
import { log as webpackHotLog } from '@rspack/core/hot/log.js';
|
|
26
26
|
import { createOverlay, formatProblem } from './overlay.js';
|
|
27
27
|
import socket from './socket.js';
|
|
28
28
|
import { defineProgressElement, isProgressSupported } from './progress.js';
|
|
@@ -86,7 +86,7 @@ var getCurrentScriptSource = function () {
|
|
|
86
86
|
return currentScript.getAttribute('src');
|
|
87
87
|
}
|
|
88
88
|
// Fail as there was no script to use.
|
|
89
|
-
throw new Error('[
|
|
89
|
+
throw new Error('[rspack-dev-server] Failed to get current script source.');
|
|
90
90
|
};
|
|
91
91
|
var parsedResourceQuery = parseURL(__resourceQuery);
|
|
92
92
|
var enabledFeatures = {
|
|
@@ -187,8 +187,8 @@ var reloadApp = function (_a, currentStatus) {
|
|
|
187
187
|
rootWindow.location.reload();
|
|
188
188
|
}
|
|
189
189
|
var search = self.location.search.toLowerCase();
|
|
190
|
-
var allowToHot = search.indexOf('
|
|
191
|
-
var allowToLiveReload = search.indexOf('
|
|
190
|
+
var allowToHot = search.indexOf('rspack-dev-server-hot=false') === -1;
|
|
191
|
+
var allowToLiveReload = search.indexOf('rspack-dev-server-live-reload=false') === -1;
|
|
192
192
|
if (hot && allowToHot) {
|
|
193
193
|
log.info('App hot update...');
|
|
194
194
|
hotEmitter.emit('webpackHotUpdate', currentStatus.currentHash);
|
|
@@ -280,7 +280,7 @@ var onSocketMessage = {
|
|
|
280
280
|
},
|
|
281
281
|
'progress-update': function progressUpdate(data) {
|
|
282
282
|
if (options.progress) {
|
|
283
|
-
log.info("".concat(data.
|
|
283
|
+
log.info("".concat(data.percent, "% - ").concat(data.msg, "."));
|
|
284
284
|
}
|
|
285
285
|
if (isProgressSupported()) {
|
|
286
286
|
if (typeof options.progress === 'string') {
|
package/client/overlay.js
CHANGED
|
@@ -340,18 +340,18 @@ var createOverlay = function (options) {
|
|
|
340
340
|
function createContainer(trustedTypesPolicyName) {
|
|
341
341
|
// Enable Trusted Types if they are available in the current browser.
|
|
342
342
|
if (window.trustedTypes) {
|
|
343
|
-
overlayTrustedTypesPolicy = window.trustedTypes.createPolicy(trustedTypesPolicyName || '
|
|
343
|
+
overlayTrustedTypesPolicy = window.trustedTypes.createPolicy(trustedTypesPolicyName || 'rspack-dev-server#overlay', {
|
|
344
344
|
createHTML: function (value) { return value; },
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
iframeContainerElement = document.createElement('iframe');
|
|
348
|
-
iframeContainerElement.id = '
|
|
348
|
+
iframeContainerElement.id = 'rspack-dev-server-client-overlay';
|
|
349
349
|
iframeContainerElement.src = 'about:blank';
|
|
350
350
|
applyStyle(iframeContainerElement, iframeStyle);
|
|
351
351
|
iframeContainerElement.onload = function () {
|
|
352
352
|
var contentElement = (iframeContainerElement === null || iframeContainerElement === void 0 ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
353
353
|
containerElement = (iframeContainerElement === null || iframeContainerElement === void 0 ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
354
|
-
contentElement.id = '
|
|
354
|
+
contentElement.id = 'rspack-dev-server-client-overlay-div';
|
|
355
355
|
applyStyle(contentElement, containerStyle);
|
|
356
356
|
headerElement = document.createElement('div');
|
|
357
357
|
headerElement.innerText = 'Compiled with problems:';
|
|
@@ -421,7 +421,7 @@ var createOverlay = function (options) {
|
|
|
421
421
|
// element.dataset not supported in IE
|
|
422
422
|
typeElement.setAttribute('data-can-open', 'true');
|
|
423
423
|
typeElement.addEventListener('click', function () {
|
|
424
|
-
fetch("/
|
|
424
|
+
fetch("/rspack-dev-server/open-editor?fileName=".concat(message.moduleIdentifier));
|
|
425
425
|
});
|
|
426
426
|
}
|
|
427
427
|
// Make it look similar to our terminal.
|
package/client/utils/ansiHTML.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Reference to https://github.com/sindresorhus/ansi-regex
|
|
2
2
|
var _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
|
|
3
3
|
var _defColors = {
|
|
4
|
-
reset: ['fff', '000'],
|
|
4
|
+
reset: ['fff', '000'], // [FOREGROUND_COLOR, BACKGROUND_COLOR]
|
|
5
5
|
black: '000',
|
|
6
6
|
red: 'ff0000',
|
|
7
7
|
green: '209805',
|
|
@@ -26,12 +26,12 @@ var _colorMode = {
|
|
|
26
26
|
2: 'rgb',
|
|
27
27
|
};
|
|
28
28
|
var _openTags = {
|
|
29
|
-
1: 'font-weight:bold',
|
|
30
|
-
2: 'opacity:0.5',
|
|
31
|
-
3: '<i>',
|
|
32
|
-
4: '<u>',
|
|
33
|
-
8: 'display:none',
|
|
34
|
-
9: '<del>',
|
|
29
|
+
1: 'font-weight:bold', // bold
|
|
30
|
+
2: 'opacity:0.5', // dim
|
|
31
|
+
3: '<i>', // italic
|
|
32
|
+
4: '<u>', // underscore
|
|
33
|
+
8: 'display:none', // hidden
|
|
34
|
+
9: '<del>', // delete
|
|
35
35
|
38: function (match) {
|
|
36
36
|
// color
|
|
37
37
|
var mode = _colorMode[match[0]];
|
|
@@ -78,8 +78,8 @@ var _closeTags = {
|
|
|
78
78
|
}
|
|
79
79
|
return ret;
|
|
80
80
|
},
|
|
81
|
-
23: '</i>',
|
|
82
|
-
24: '</u>',
|
|
81
|
+
23: '</i>', // reset italic
|
|
82
|
+
24: '</u>', // reset underscore
|
|
83
83
|
29: '</del>', // reset delete
|
|
84
84
|
};
|
|
85
85
|
for (var _i = 0, _a = [21, 22, 27, 28, 39, 49]; _i < _a.length; _i++) {
|
package/client/utils/log.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
9
|
*/
|
|
10
10
|
import logger from '../modules/logger/index';
|
|
11
|
-
var name = '
|
|
11
|
+
var name = 'rspack-dev-server';
|
|
12
12
|
// default level is set on the client side, so it does not need
|
|
13
13
|
// to be set by the CLI or API
|
|
14
14
|
var defaultLevel = 'info';
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import type { BonjourOptions, ClientConfiguration, ConnectHistoryApiFallbackOptions, DevServer, NormalizedStatic, Open, ServerConfiguration, WatchFiles, WebSocketServerConfiguration } from './types';
|
|
1
|
+
import type { ClientConfiguration, ConnectHistoryApiFallbackOptions, DevServer, NormalizedStatic, Open, ServerConfiguration, WatchFiles, WebSocketServerConfiguration } from './types';
|
|
3
2
|
export interface ResolvedDevServer extends DevServer {
|
|
4
3
|
port: number | string;
|
|
5
4
|
static: false | Array<NormalizedStatic>;
|
|
@@ -13,7 +12,6 @@ export interface ResolvedDevServer extends DevServer {
|
|
|
13
12
|
proxy: Required<DevServer['proxy']>;
|
|
14
13
|
client: ClientConfiguration;
|
|
15
14
|
allowedHosts: 'auto' | string[] | 'all';
|
|
16
|
-
bonjour: false | Record<string, never> | BonjourOptions;
|
|
17
15
|
compress: boolean;
|
|
18
16
|
historyApiFallback: false | ConnectHistoryApiFallbackOptions;
|
|
19
17
|
server: ServerConfiguration;
|
package/dist/getPort.js
CHANGED
|
@@ -24,13 +24,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
24
24
|
}) : function(o, v) {
|
|
25
25
|
o["default"] = v;
|
|
26
26
|
});
|
|
27
|
-
var __importStar = (this && this.__importStar) || function (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
34
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
45
|
/*
|
|
36
46
|
* Based on the packages get-port https://www.npmjs.com/package/get-port
|
|
@@ -41,7 +51,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
41
51
|
const net = __importStar(require("node:net"));
|
|
42
52
|
const os = __importStar(require("node:os"));
|
|
43
53
|
const minPort = 1024;
|
|
44
|
-
const maxPort =
|
|
54
|
+
const maxPort = 65_535;
|
|
45
55
|
/**
|
|
46
56
|
* Get all local hosts
|
|
47
57
|
*/
|
package/dist/server.d.ts
CHANGED
|
@@ -7,11 +7,7 @@
|
|
|
7
7
|
* Copyright (c) JS Foundation and other contributors
|
|
8
8
|
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
/// <reference types="node" />
|
|
12
|
-
/// <reference types="connect-history-api-fallback" />
|
|
13
|
-
/// <reference types="node" />
|
|
14
|
-
import type { BasicApplication, ExpressApplication, HTTPServer, Response, Request, Host, Port, DevMiddlewareOptions, ConnectHistoryApiFallbackOptions, BonjourOptions, WatchFiles, Static, ServerType, ServerConfiguration, WebSocketServerConfiguration, ProxyConfigArray, Open, ClientConfiguration, Middleware, DevMiddlewareContext, Compiler, MultiCompiler, FSWatcher, EXPECTED_ANY, RequestHandler, Socket, Bonjour, WebSocketServerImplementation, Stats, MultiStats, DevServer, Schema, StatsOptions, WatchOptions, StatsCompilation, NextFunction, ClientConnection, Headers } from './types';
|
|
10
|
+
import type { BasicApplication, ClientConfiguration, ClientConnection, Compiler, ConnectHistoryApiFallbackOptions, DevMiddlewareContext, DevMiddlewareOptions, DevServer, EXPECTED_ANY, ExpressApplication, FSWatcher, HTTPServer, Headers, Host, Middleware, MultiCompiler, MultiStats, NextFunction, Open, Port, ProxyConfigArray, Request, RequestHandler, Response, ServerConfiguration, ServerType, Socket, Static, Stats, StatsCompilation, StatsOptions, WatchFiles, WatchOptions, WebSocketServerConfiguration, WebSocketServerImplementation } from './types';
|
|
15
11
|
export interface Configuration<A extends BasicApplication = ExpressApplication, S extends HTTPServer = HTTPServer> {
|
|
16
12
|
ipc?: boolean | string;
|
|
17
13
|
host?: Host;
|
|
@@ -22,12 +18,11 @@ export interface Configuration<A extends BasicApplication = ExpressApplication,
|
|
|
22
18
|
compress?: boolean;
|
|
23
19
|
allowedHosts?: 'auto' | 'all' | string | string[];
|
|
24
20
|
historyApiFallback?: boolean | ConnectHistoryApiFallbackOptions;
|
|
25
|
-
bonjour?: boolean | Record<string, never> | BonjourOptions;
|
|
26
21
|
watchFiles?: string | string[] | WatchFiles | Array<string | WatchFiles>;
|
|
27
22
|
static?: boolean | string | Static | Array<string | Static>;
|
|
28
23
|
server?: ServerType<A, S> | ServerConfiguration<A, S>;
|
|
29
24
|
app?: () => Promise<A>;
|
|
30
|
-
webSocketServer?: boolean | '
|
|
25
|
+
webSocketServer?: boolean | 'ws' | string | WebSocketServerConfiguration;
|
|
31
26
|
proxy?: ProxyConfigArray;
|
|
32
27
|
open?: boolean | string | Open | Array<string | Open>;
|
|
33
28
|
setupExitSignals?: boolean;
|
|
@@ -49,36 +44,32 @@ declare class Server<A extends BasicApplication = ExpressApplication, S extends
|
|
|
49
44
|
sockets: Socket[];
|
|
50
45
|
currentHash: string | undefined;
|
|
51
46
|
isTlsServer: boolean;
|
|
52
|
-
bonjour: Bonjour | undefined;
|
|
53
47
|
webSocketServer: WebSocketServerImplementation | null | undefined;
|
|
54
48
|
middleware: import('webpack-dev-middleware').API<Request, Response> | undefined;
|
|
55
49
|
server: S | undefined;
|
|
56
50
|
app: A | undefined;
|
|
57
51
|
stats: Stats | MultiStats | undefined;
|
|
58
52
|
constructor(options: DevServer, compiler: Compiler | MultiCompiler);
|
|
59
|
-
static get schema(): Schema;
|
|
60
53
|
static get DEFAULT_STATS(): StatsOptions;
|
|
61
54
|
static isAbsoluteURL(URL: string): boolean;
|
|
62
55
|
static findIp(gatewayOrFamily: string, isInternal: boolean): string | undefined;
|
|
63
|
-
static internalIP(family: 'v4' | 'v6'): Promise<string | undefined>;
|
|
64
|
-
static internalIPSync(family: 'v4' | 'v6'): string | undefined;
|
|
65
56
|
static getHostname(hostname: Host): Promise<string>;
|
|
66
57
|
static getFreePort(port: string, host: string): Promise<any>;
|
|
67
58
|
static findCacheDir(): string;
|
|
68
|
-
static isWebTarget(compiler: Compiler): boolean;
|
|
69
59
|
addAdditionalEntries(compiler: Compiler): void;
|
|
70
60
|
/**
|
|
71
61
|
* @private
|
|
72
62
|
* @returns {Compiler["options"]} compiler options
|
|
73
63
|
*/
|
|
74
|
-
getCompilerOptions(): import("@rspack/core").RspackOptionsNormalized;
|
|
64
|
+
getCompilerOptions(): import("@rspack/core", { with: { "resolution-mode": "import" } }).RspackOptionsNormalized;
|
|
65
|
+
shouldLogInfrastructureInfo(): boolean;
|
|
75
66
|
normalizeOptions(): Promise<void>;
|
|
76
67
|
/**
|
|
77
68
|
* @private
|
|
78
69
|
* @returns {string} client transport
|
|
79
70
|
*/
|
|
80
71
|
getClientTransport(): string;
|
|
81
|
-
getServerTransport(): typeof import("./servers/
|
|
72
|
+
getServerTransport(): typeof import("./servers/WebsocketServer") | undefined;
|
|
82
73
|
getClientEntry(): string;
|
|
83
74
|
getClientHotEntry(): string | undefined;
|
|
84
75
|
setupProgressPlugin(): void;
|
|
@@ -100,8 +91,6 @@ declare class Server<A extends BasicApplication = ExpressApplication, S extends
|
|
|
100
91
|
createServer(): Promise<void>;
|
|
101
92
|
createWebSocketServer(): void;
|
|
102
93
|
openBrowser(defaultOpenTarget: string): Promise<void>;
|
|
103
|
-
runBonjour(): void;
|
|
104
|
-
stopBonjour(callback?: () => void): void;
|
|
105
94
|
logStatus(): Promise<void>;
|
|
106
95
|
setHeaders(req: Request, res: Response, next: NextFunction): void;
|
|
107
96
|
isHostAllowed(value: string): boolean;
|