@rspack/dev-server 1.0.6 → 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.js +10 -0
- 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.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeResolveAlias = exports.addResolveAlias = void 0;
|
|
4
|
+
const Module = require("module");
|
|
5
|
+
const MODULE_MAP = {};
|
|
4
6
|
const RESOLVER_MAP = {};
|
|
5
7
|
const addResolveAlias = (name, aliasMap) => {
|
|
6
8
|
const modulePath = require.resolve(name);
|
|
@@ -17,6 +19,13 @@ const addResolveAlias = (name, aliasMap) => {
|
|
|
17
19
|
id,
|
|
18
20
|
options
|
|
19
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
|
+
};
|
|
20
29
|
};
|
|
21
30
|
exports.addResolveAlias = addResolveAlias;
|
|
22
31
|
const removeResolveAlias = (name) => {
|
|
@@ -29,6 +38,7 @@ const removeResolveAlias = (name) => {
|
|
|
29
38
|
throw new Error("Failed to resolve webpack-dev-server");
|
|
30
39
|
}
|
|
31
40
|
if (RESOLVER_MAP[modulePath]) {
|
|
41
|
+
Module._resolveFilename = RESOLVER_MAP[modulePath];
|
|
32
42
|
m.require.resolve = RESOLVER_MAP[modulePath];
|
|
33
43
|
delete RESOLVER_MAP[modulePath];
|
|
34
44
|
}
|
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
|
}
|