@rspack/dev-server 1.0.5 → 1.0.7
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 +100 -4
- package/client/index.js +1 -0
- package/dist/alias.d.ts +2 -0
- package/dist/alias.js +46 -0
- package/dist/server.d.ts +0 -3
- package/dist/server.js +14 -273
- package/package.json +37 -10
package/README.md
CHANGED
|
@@ -5,12 +5,108 @@
|
|
|
5
5
|
|
|
6
6
|
# @rspack/dev-server
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use Rspack with a development server that provides live reloading. This should be used for development only.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
> `@rspack/dev-server` is based on `webpack-dev-server@5`
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
First of all, install `@rspack/dev-server` and `@rspack/core` by your favorite package manager:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# npm
|
|
18
|
+
$ npm install @rspack/dev-server @rspack/core --save-dev
|
|
19
|
+
|
|
20
|
+
# yarn
|
|
21
|
+
$ yarn add @rspack/dev-server @rspack/core --dev
|
|
22
|
+
|
|
23
|
+
# pnpm
|
|
24
|
+
$ pnpm add @rspack/dev-server @rspack/core --save-dev
|
|
25
|
+
|
|
26
|
+
# bun
|
|
27
|
+
$ bun add @rspack/dev-server @rspack/core -D
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
There are two recommended ways to use `@rspack/dev-server`:
|
|
33
|
+
|
|
34
|
+
### With the CLI
|
|
35
|
+
|
|
36
|
+
The easiest way to use it is with the [`@rspack/cli`](https://www.npmjs.com/package/@rspack/cli).
|
|
37
|
+
|
|
38
|
+
You can install it in your project by:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# npm
|
|
42
|
+
$ npm install @rspack/cli --save-dev
|
|
43
|
+
|
|
44
|
+
# yarn
|
|
45
|
+
$ yarn add @rspack/cli --dev
|
|
46
|
+
|
|
47
|
+
# pnpm
|
|
48
|
+
$ pnpm add @rspack/cli --save-dev
|
|
49
|
+
|
|
50
|
+
# bun
|
|
51
|
+
$ bun add @rspack/cli -D
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
And then start the development server by:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# with rspack.config.js
|
|
58
|
+
$ rspack serve
|
|
59
|
+
|
|
60
|
+
# with custom config file
|
|
61
|
+
$ rspack serve -c ./your.config.js
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> See [CLI](https://rspack.dev/api/cli) for more details.
|
|
65
|
+
|
|
66
|
+
While starting the development server, you can specify the configuration by the `devServer` field of your Rspack config file:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
// rspack.config.js
|
|
70
|
+
module.exports = {
|
|
71
|
+
// ...
|
|
72
|
+
devServer: {
|
|
73
|
+
// the configuration of the development server
|
|
74
|
+
port: 8080
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
> See [DevServer](https://rspack.dev/config/dev-server) for all configuration options.
|
|
80
|
+
|
|
81
|
+
### With the API
|
|
82
|
+
|
|
83
|
+
While it's recommended to run `@rspack/dev-server` via the CLI, you may also choose to start a server via the API.
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
import { RspackDevServer } from "@rspack/dev-server";
|
|
87
|
+
import rspack from "@rspack/core";
|
|
88
|
+
import rspackConfig from './rspack.config.js';
|
|
89
|
+
|
|
90
|
+
const compiler = rspack(rspackConfig);
|
|
91
|
+
const devServerOptions = {
|
|
92
|
+
...rspackConfig.devServer,
|
|
93
|
+
// override
|
|
94
|
+
port: 8888
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const server = new RspackDevServer(devServerOptions, compiler);
|
|
98
|
+
|
|
99
|
+
server.startCallback(() => {
|
|
100
|
+
console.log('Successfully started server on http://localhost:8888');
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
> 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.
|
|
105
|
+
|
|
106
|
+
## Credits
|
|
107
|
+
|
|
108
|
+
Thanks to the [webpack-dev-server](https://github.com/webpack/webpack-dev-server) project created by [@sokra](https://github.com/sokra)
|
|
13
109
|
|
|
14
110
|
## License
|
|
15
111
|
|
|
16
|
-
|
|
112
|
+
[MIT licensed](https://github.com/web-infra-dev/rspack-dev-server/blob/main/LICENSE).
|
package/client/index.js
CHANGED
package/dist/alias.d.ts
ADDED
package/dist/alias.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeResolveAlias = exports.addResolveAlias = void 0;
|
|
4
|
+
const Module = require("module");
|
|
5
|
+
const MODULE_MAP = {};
|
|
6
|
+
const RESOLVER_MAP = {};
|
|
7
|
+
const addResolveAlias = (name, aliasMap) => {
|
|
8
|
+
const modulePath = require.resolve(name);
|
|
9
|
+
if (RESOLVER_MAP[modulePath]) {
|
|
10
|
+
throw new Error(`Should not add resolve alias to ${name} again.`);
|
|
11
|
+
}
|
|
12
|
+
const m = require.cache[modulePath];
|
|
13
|
+
if (!m) {
|
|
14
|
+
throw new Error("Failed to resolve webpack-dev-server.");
|
|
15
|
+
}
|
|
16
|
+
RESOLVER_MAP[modulePath] = m.require.resolve;
|
|
17
|
+
m.require.resolve = ((id, options) => aliasMap[id] ||
|
|
18
|
+
RESOLVER_MAP[modulePath].apply(m.require, [
|
|
19
|
+
id,
|
|
20
|
+
options
|
|
21
|
+
]));
|
|
22
|
+
MODULE_MAP[modulePath] = Module._resolveFilename;
|
|
23
|
+
Module._resolveFilename = Module._resolveFilename = (request, mod, ...args) => {
|
|
24
|
+
if (mod.filename === modulePath && aliasMap[request]) {
|
|
25
|
+
return aliasMap[request];
|
|
26
|
+
}
|
|
27
|
+
return MODULE_MAP[modulePath](request, mod, ...args);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.addResolveAlias = addResolveAlias;
|
|
31
|
+
const removeResolveAlias = (name) => {
|
|
32
|
+
const modulePath = require.resolve(name);
|
|
33
|
+
if (!RESOLVER_MAP[modulePath]) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const m = require.cache[modulePath];
|
|
37
|
+
if (!m) {
|
|
38
|
+
throw new Error("Failed to resolve webpack-dev-server");
|
|
39
|
+
}
|
|
40
|
+
if (RESOLVER_MAP[modulePath]) {
|
|
41
|
+
Module._resolveFilename = RESOLVER_MAP[modulePath];
|
|
42
|
+
m.require.resolve = RESOLVER_MAP[modulePath];
|
|
43
|
+
delete RESOLVER_MAP[modulePath];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.removeResolveAlias = removeResolveAlias;
|
package/dist/server.d.ts
CHANGED
|
@@ -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,15 +15,12 @@ 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
|
-
const encodeOverlaySettings = (setting) => typeof setting === "function"
|
|
25
|
-
? encodeURIComponent(setting.toString())
|
|
26
|
-
: setting;
|
|
27
24
|
const getFreePort = async function getFreePort(port, host) {
|
|
28
25
|
if (typeof port !== "undefined" && port !== null && port !== "auto") {
|
|
29
26
|
return port;
|
|
@@ -46,60 +43,7 @@ webpack_dev_server_1.default.getFreePort = getFreePort;
|
|
|
46
43
|
class RspackDevServer extends webpack_dev_server_1.default {
|
|
47
44
|
constructor(options, compiler) {
|
|
48
45
|
super(options, compiler);
|
|
49
|
-
|
|
50
|
-
getClientTransport() {
|
|
51
|
-
// WARNING: we can't use `super.getClientTransport`,
|
|
52
|
-
// because we doesn't had same directory structure.
|
|
53
|
-
let clientImplementation;
|
|
54
|
-
let clientImplementationFound = true;
|
|
55
|
-
const isKnownWebSocketServerImplementation = this.options.webSocketServer &&
|
|
56
|
-
typeof this.options.webSocketServer.type === "string" &&
|
|
57
|
-
(this.options.webSocketServer.type === "ws" ||
|
|
58
|
-
this.options.webSocketServer.type === "sockjs");
|
|
59
|
-
let clientTransport;
|
|
60
|
-
if (this.options.client) {
|
|
61
|
-
if (typeof this.options.client.webSocketTransport !== "undefined") {
|
|
62
|
-
clientTransport = this.options.client.webSocketTransport;
|
|
63
|
-
}
|
|
64
|
-
else if (isKnownWebSocketServerImplementation) {
|
|
65
|
-
// @ts-expect-error: TS cannot infer webSocketServer is narrowed
|
|
66
|
-
clientTransport = this.options.webSocketServer.type;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
clientTransport = "ws";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
clientTransport = "ws";
|
|
74
|
-
}
|
|
75
|
-
switch (typeof clientTransport) {
|
|
76
|
-
case "string":
|
|
77
|
-
// could be 'sockjs', 'ws', or a path that should be required
|
|
78
|
-
if (clientTransport === "sockjs") {
|
|
79
|
-
clientImplementation = require.resolve("webpack-dev-server/client/clients/SockJSClient");
|
|
80
|
-
}
|
|
81
|
-
else if (clientTransport === "ws") {
|
|
82
|
-
clientImplementation = require.resolve("webpack-dev-server/client/clients/WebSocketClient");
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
try {
|
|
86
|
-
clientImplementation = require.resolve(clientTransport);
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
clientImplementationFound = false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
default:
|
|
94
|
-
clientImplementationFound = false;
|
|
95
|
-
}
|
|
96
|
-
if (!clientImplementationFound) {
|
|
97
|
-
throw new Error(`${!isKnownWebSocketServerImplementation
|
|
98
|
-
? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. "
|
|
99
|
-
: ""}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 `);
|
|
100
|
-
}
|
|
101
|
-
// @ts-expect-error
|
|
102
|
-
return clientImplementation;
|
|
46
|
+
// override
|
|
103
47
|
}
|
|
104
48
|
async initialize() {
|
|
105
49
|
const compilers = this.compiler instanceof core_1.MultiCompiler
|
|
@@ -112,231 +56,28 @@ class RspackDevServer extends webpack_dev_server_1.default {
|
|
|
112
56
|
this.logger.warn("Hot Module Replacement (HMR) is enabled for the production build. \n" +
|
|
113
57
|
"Make sure to disable HMR for production by setting `devServer.hot` to `false` in the configuration.");
|
|
114
58
|
}
|
|
115
|
-
const HMRPluginExists = compiler.options.plugins.find(p => p?.constructor === compiler.webpack.HotModuleReplacementPlugin);
|
|
116
|
-
if (HMRPluginExists) {
|
|
117
|
-
this.logger.warn(`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// Apply the HMR plugin
|
|
121
|
-
const plugin = new compiler.webpack.HotModuleReplacementPlugin();
|
|
122
|
-
plugin.apply(compiler);
|
|
123
|
-
}
|
|
124
|
-
// Apply modified version of `ansi-html-community`
|
|
125
59
|
compiler.options.resolve.alias = {
|
|
126
60
|
"ansi-html-community": node_path_1.default.resolve(__dirname, "./ansiHTML"),
|
|
127
61
|
...compiler.options.resolve.alias
|
|
128
62
|
};
|
|
129
63
|
}
|
|
130
64
|
}
|
|
131
|
-
if (this.options.webSocketServer) {
|
|
132
|
-
for (const compiler of compilers) {
|
|
133
|
-
this.addAdditionalEntries(compiler);
|
|
134
|
-
new compiler.webpack.ProvidePlugin({
|
|
135
|
-
__webpack_dev_server_client__: this.getClientTransport()
|
|
136
|
-
}).apply(compiler);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
// @ts-expect-error: `setupHooks` is private function in base class.
|
|
140
|
-
this.setupHooks();
|
|
141
|
-
// @ts-expect-error: `setupApp` is private function in base class.
|
|
142
|
-
this.setupApp();
|
|
143
|
-
// @ts-expect-error: `setupHostHeaderCheck` is private function in base class.
|
|
144
|
-
this.setupHostHeaderCheck();
|
|
145
|
-
this.setupDevMiddleware();
|
|
146
|
-
// @ts-expect-error: `setupBuiltInRoutes` is private function in base class.
|
|
147
|
-
this.setupBuiltInRoutes();
|
|
148
|
-
// @ts-expect-error: `setupWatchFiles` is private function in base class.
|
|
149
|
-
this.setupWatchFiles();
|
|
150
|
-
// @ts-expect-error: `setupWatchStaticFiles` is private function in base class.
|
|
151
|
-
this.setupWatchStaticFiles();
|
|
152
|
-
this.setupMiddlewares();
|
|
153
|
-
// @ts-expect-error: `createServer` is private function in base class.
|
|
154
|
-
this.createServer();
|
|
155
|
-
if (this.options.setupExitSignals) {
|
|
156
|
-
const signals = ["SIGINT", "SIGTERM"];
|
|
157
|
-
let needForceShutdown = false;
|
|
158
|
-
for (const signal of signals) {
|
|
159
|
-
const listener = () => {
|
|
160
|
-
if (needForceShutdown) {
|
|
161
|
-
process.exit();
|
|
162
|
-
}
|
|
163
|
-
this.logger.info("Gracefully shutting down. To force exit, press ^C again. Please wait...");
|
|
164
|
-
needForceShutdown = true;
|
|
165
|
-
this.stopCallback(() => {
|
|
166
|
-
if (typeof this.compiler.close === "function") {
|
|
167
|
-
this.compiler.close(() => {
|
|
168
|
-
process.exit();
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
process.exit();
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
// @ts-expect-error: `listeners` is private function in base class.
|
|
177
|
-
this.listeners.push({ name: signal, listener });
|
|
178
|
-
process.on(signal, listener);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// Proxy WebSocket without the initial http request
|
|
182
|
-
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
|
|
183
|
-
// @ts-expect-error: `webSocketProxies` is private function in base class.
|
|
184
|
-
for (const webSocketProxy of this.webSocketProxies) {
|
|
185
|
-
this.server.on("upgrade", webSocketProxy.upgrade);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
setupDevMiddleware() {
|
|
189
|
-
// @ts-expect-error
|
|
190
|
-
this.middleware = (0, webpack_dev_middleware_1.default)(this.compiler, this.options.devMiddleware);
|
|
191
|
-
}
|
|
192
|
-
setupMiddlewares() {
|
|
193
|
-
const middlewares = [];
|
|
194
|
-
for (const middleware of middlewares) {
|
|
195
|
-
if (typeof middleware === "function") {
|
|
196
|
-
// @ts-expect-error
|
|
197
|
-
this.app.use(middleware);
|
|
198
|
-
}
|
|
199
|
-
else if (typeof middleware.path !== "undefined") {
|
|
200
|
-
// @ts-expect-error
|
|
201
|
-
this.app.use(middleware.path, middleware.middleware);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
// @ts-expect-error
|
|
205
|
-
this.app.use(middleware.middleware);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
65
|
// @ts-expect-error
|
|
209
|
-
super.
|
|
66
|
+
await super.initialize();
|
|
210
67
|
}
|
|
68
|
+
// @ts-ignore
|
|
211
69
|
addAdditionalEntries(compiler) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
.webSocketURL;
|
|
221
|
-
const webSocketServer = this.options.webSocketServer;
|
|
222
|
-
const searchParams = new URLSearchParams();
|
|
223
|
-
let protocol;
|
|
224
|
-
// We are proxying dev server and need to specify custom `hostname`
|
|
225
|
-
if (typeof webSocketURL.protocol !== "undefined") {
|
|
226
|
-
protocol = webSocketURL.protocol;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
protocol = this.options.server.type === "http" ? "ws:" : "wss:";
|
|
230
|
-
}
|
|
231
|
-
searchParams.set("protocol", protocol);
|
|
232
|
-
if (typeof webSocketURL.username !== "undefined") {
|
|
233
|
-
searchParams.set("username", webSocketURL.username);
|
|
234
|
-
}
|
|
235
|
-
if (typeof webSocketURL.password !== "undefined") {
|
|
236
|
-
searchParams.set("password", webSocketURL.password);
|
|
237
|
-
}
|
|
238
|
-
let hostname;
|
|
239
|
-
// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
|
|
240
|
-
// TODO show warning about this
|
|
241
|
-
const isSockJSType = webSocketServer.type === "sockjs";
|
|
242
|
-
// We are proxying dev server and need to specify custom `hostname`
|
|
243
|
-
if (typeof webSocketURL.hostname !== "undefined") {
|
|
244
|
-
hostname = webSocketURL.hostname;
|
|
245
|
-
}
|
|
246
|
-
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
|
|
247
|
-
else if (typeof webSocketServer.options?.host !== "undefined" &&
|
|
248
|
-
!isSockJSType) {
|
|
249
|
-
hostname = webSocketServer.options.host;
|
|
250
|
-
}
|
|
251
|
-
// The `host` option is specified
|
|
252
|
-
else if (typeof this.options.host !== "undefined") {
|
|
253
|
-
hostname = this.options.host;
|
|
254
|
-
}
|
|
255
|
-
// The `port` option is not specified
|
|
256
|
-
else {
|
|
257
|
-
hostname = "0.0.0.0";
|
|
258
|
-
}
|
|
259
|
-
searchParams.set("hostname", hostname);
|
|
260
|
-
let port;
|
|
261
|
-
// We are proxying dev server and need to specify custom `port`
|
|
262
|
-
if (typeof webSocketURL.port !== "undefined") {
|
|
263
|
-
port = webSocketURL.port;
|
|
264
|
-
}
|
|
265
|
-
// Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
|
|
266
|
-
else if (typeof webSocketServer.options?.port !== "undefined" &&
|
|
267
|
-
!isSockJSType) {
|
|
268
|
-
port = webSocketServer.options.port;
|
|
269
|
-
}
|
|
270
|
-
// The `port` option is specified
|
|
271
|
-
else if (typeof this.options.port === "number") {
|
|
272
|
-
port = this.options.port;
|
|
273
|
-
}
|
|
274
|
-
// The `port` option is specified using `string`
|
|
275
|
-
else if (typeof this.options.port === "string" &&
|
|
276
|
-
this.options.port !== "auto") {
|
|
277
|
-
port = Number(this.options.port);
|
|
278
|
-
}
|
|
279
|
-
// The `port` option is not specified or set to `auto`
|
|
280
|
-
else {
|
|
281
|
-
port = "0";
|
|
282
|
-
}
|
|
283
|
-
searchParams.set("port", String(port));
|
|
284
|
-
let pathname = "";
|
|
285
|
-
// We are proxying dev server and need to specify custom `pathname`
|
|
286
|
-
if (typeof webSocketURL.pathname !== "undefined") {
|
|
287
|
-
pathname = webSocketURL.pathname;
|
|
288
|
-
}
|
|
289
|
-
// Web socket server works on custom `path`
|
|
290
|
-
else if (typeof webSocketServer.options?.prefix !== "undefined" ||
|
|
291
|
-
typeof webSocketServer.options?.path !== "undefined") {
|
|
292
|
-
pathname =
|
|
293
|
-
webSocketServer.options.prefix || webSocketServer.options.path;
|
|
294
|
-
}
|
|
295
|
-
searchParams.set("pathname", pathname);
|
|
296
|
-
const client = /** @type {ClientConfiguration} */ this.options.client;
|
|
297
|
-
if (typeof client.logging !== "undefined") {
|
|
298
|
-
searchParams.set("logging", client.logging);
|
|
299
|
-
}
|
|
300
|
-
if (typeof client.progress !== "undefined") {
|
|
301
|
-
searchParams.set("progress", String(client.progress));
|
|
302
|
-
}
|
|
303
|
-
if (typeof client.overlay !== "undefined") {
|
|
304
|
-
const overlayString = typeof client.overlay === "boolean"
|
|
305
|
-
? String(client.overlay)
|
|
306
|
-
: JSON.stringify({
|
|
307
|
-
...client.overlay,
|
|
308
|
-
errors: encodeOverlaySettings(client.overlay.errors),
|
|
309
|
-
warnings: encodeOverlaySettings(client.overlay.warnings),
|
|
310
|
-
runtimeErrors: encodeOverlaySettings(client.overlay.runtimeErrors)
|
|
311
|
-
});
|
|
312
|
-
searchParams.set("overlay", overlayString);
|
|
313
|
-
}
|
|
314
|
-
if (typeof client.reconnect !== "undefined") {
|
|
315
|
-
searchParams.set("reconnect", typeof client.reconnect === "number"
|
|
316
|
-
? String(client.reconnect)
|
|
317
|
-
: "10");
|
|
318
|
-
}
|
|
319
|
-
if (typeof this.options.hot !== "undefined") {
|
|
320
|
-
searchParams.set("hot", String(this.options.hot));
|
|
321
|
-
}
|
|
322
|
-
if (typeof this.options.liveReload !== "undefined") {
|
|
323
|
-
searchParams.set("live-reload", String(this.options.liveReload));
|
|
324
|
-
}
|
|
325
|
-
webSocketURLStr = searchParams.toString();
|
|
326
|
-
}
|
|
327
|
-
additionalEntries.push(`${require.resolve("@rspack/dev-server/client/index")}?${webSocketURLStr}`);
|
|
328
|
-
}
|
|
329
|
-
if (this.options.hot === "only") {
|
|
330
|
-
additionalEntries.push(require.resolve("@rspack/core/hot/only-dev-server"));
|
|
331
|
-
}
|
|
332
|
-
else if (this.options.hot) {
|
|
333
|
-
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);
|
|
334
78
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
new webpack.EntryPlugin(compiler.context, additionalEntry, {
|
|
338
|
-
name: undefined
|
|
339
|
-
}).apply(compiler);
|
|
79
|
+
finally {
|
|
80
|
+
(0, alias_1.removeResolveAlias)("webpack-dev-server");
|
|
340
81
|
}
|
|
341
82
|
}
|
|
342
83
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/dev-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Development server for rspack",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/",
|
|
10
11
|
"provenance": true
|
|
11
12
|
},
|
|
12
13
|
"exports": {
|
|
@@ -17,19 +18,28 @@
|
|
|
17
18
|
"./client/*.js": "./client/*.js",
|
|
18
19
|
"./package.json": "./package.json"
|
|
19
20
|
},
|
|
21
|
+
"simple-git-hooks": {
|
|
22
|
+
"pre-commit": "npx nano-staged"
|
|
23
|
+
},
|
|
24
|
+
"nano-staged": {
|
|
25
|
+
"*.{js,jsx,ts,tsx,mjs,cjs}": [
|
|
26
|
+
"biome check --write --no-errors-on-unmatched"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
20
29
|
"files": [
|
|
21
30
|
"dist",
|
|
22
31
|
"client"
|
|
23
32
|
],
|
|
24
33
|
"homepage": "https://rspack.dev",
|
|
25
|
-
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
|
34
|
+
"bugs": "https://github.com/web-infra-dev/rspack-dev-server/issues",
|
|
26
35
|
"repository": {
|
|
27
36
|
"type": "git",
|
|
28
|
-
"url": "https://github.com/web-infra-dev/rspack"
|
|
29
|
-
"directory": "packages/rspack-dev-server"
|
|
37
|
+
"url": "https://github.com/web-infra-dev/rspack-dev-server"
|
|
30
38
|
},
|
|
31
39
|
"devDependencies": {
|
|
40
|
+
"@biomejs/biome": "^1.8.3",
|
|
32
41
|
"@jest/test-sequencer": "^29.7.0",
|
|
42
|
+
"@rspack/core": "1.0.6",
|
|
33
43
|
"@rspack/plugin-react-refresh": "1.0.0",
|
|
34
44
|
"@types/connect-history-api-fallback": "1.5.4",
|
|
35
45
|
"@types/express": "4.17.21",
|
|
@@ -48,8 +58,23 @@
|
|
|
48
58
|
"tcp-port-used": "^1.0.2",
|
|
49
59
|
"typescript": "5.0.2",
|
|
50
60
|
"wait-for-expect": "^3.0.2",
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
61
|
+
"@jest/reporters": "29.7.0",
|
|
62
|
+
"@types/jest": "29.5.12",
|
|
63
|
+
"cross-env": "^7.0.3",
|
|
64
|
+
"husky": "^9.0.0",
|
|
65
|
+
"jest": "29.7.0",
|
|
66
|
+
"jest-cli": "29.7.0",
|
|
67
|
+
"jest-environment-node": "29.7.0",
|
|
68
|
+
"rimraf": "3.0.2",
|
|
69
|
+
"ts-jest": "29.1.2",
|
|
70
|
+
"webpack": "^5.94.0",
|
|
71
|
+
"webpack-cli": "5.1.4",
|
|
72
|
+
"react-refresh": "0.14.0",
|
|
73
|
+
"execa": "9.3.0",
|
|
74
|
+
"fs-extra": "11.2.0",
|
|
75
|
+
"nano-staged": "^0.8.0",
|
|
76
|
+
"semver": "7.6.3",
|
|
77
|
+
"simple-git-hooks": "^2.11.1"
|
|
53
78
|
},
|
|
54
79
|
"dependencies": {
|
|
55
80
|
"chokidar": "^3.6.0",
|
|
@@ -67,10 +92,12 @@
|
|
|
67
92
|
},
|
|
68
93
|
"scripts": {
|
|
69
94
|
"build": "tsc -b ./tsconfig.build.json",
|
|
70
|
-
"dev": "tsc -
|
|
95
|
+
"dev": "tsc -b -w",
|
|
96
|
+
"lint": "biome check .",
|
|
97
|
+
"lint:write": "biome check . --write",
|
|
98
|
+
"format": "node ./node_modules/prettier/bin/prettier.cjs \"packages/**/src/**/*.{ts,tsx,js}\" \"crates/rspack_plugin_runtime/**/*.{ts,js}\" \"x.mjs\" --check",
|
|
71
99
|
"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
|
|
73
|
-
"
|
|
74
|
-
"api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
|
|
100
|
+
"test": "pnpm run test:install && pnpm run build && cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ./node_modules/jest-cli/bin/jest --colors",
|
|
101
|
+
"release": "node ./scripts/release.mjs"
|
|
75
102
|
}
|
|
76
103
|
}
|