@rspack/dev-server 1.0.6 → 1.0.8

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 CHANGED
@@ -5,12 +5,108 @@
5
5
 
6
6
  # @rspack/dev-server
7
7
 
8
- Development server for rspack.
8
+ Use Rspack with a development server that provides live reloading. This should be used for development only.
9
9
 
10
- ## Documentation
10
+ > `@rspack/dev-server` is based on `webpack-dev-server@5`
11
11
 
12
- See [https://rspack.dev](https://rspack.dev) for details.
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
- Rspack is [MIT licensed](https://github.com/web-infra-dev/rspack/blob/main/LICENSE).
112
+ [MIT licensed](https://github.com/web-infra-dev/rspack-dev-server/blob/main/LICENSE).
package/client/index.js CHANGED
@@ -216,6 +216,7 @@ var overlay =
216
216
  : {
217
217
  send: function send() {}
218
218
  };
219
+ /* Rspack dev server runtime client */
219
220
  var onSocketMessage = {
220
221
  hot: function hot() {
221
222
  if (parsedResourceQuery.hot === "false") {
package/dist/alias.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeResolveAlias = exports.addResolveAlias = void 0;
4
+ const Module = require("node:module");
5
+ const MODULE_MAP = {};
4
6
  const RESOLVER_MAP = {};
5
7
  const addResolveAlias = (name, aliasMap) => {
6
8
  const modulePath = require.resolve(name);
7
- if (RESOLVER_MAP[modulePath]) {
9
+ if (modulePath in RESOLVER_MAP) {
8
10
  throw new Error(`Should not add resolve alias to ${name} again.`);
9
11
  }
10
12
  const m = require.cache[modulePath];
@@ -12,25 +14,32 @@ const addResolveAlias = (name, aliasMap) => {
12
14
  throw new Error("Failed to resolve webpack-dev-server.");
13
15
  }
14
16
  RESOLVER_MAP[modulePath] = m.require.resolve;
17
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
15
18
  m.require.resolve = ((id, options) => aliasMap[id] ||
16
19
  RESOLVER_MAP[modulePath].apply(m.require, [
17
20
  id,
18
- options
21
+ options,
19
22
  ]));
23
+ MODULE_MAP[modulePath] = Module._resolveFilename;
24
+ Module._resolveFilename = (request, mod, ...args) => {
25
+ if (mod.filename === modulePath && aliasMap[request]) {
26
+ return aliasMap[request];
27
+ }
28
+ return MODULE_MAP[modulePath](request, mod, ...args);
29
+ };
20
30
  };
21
31
  exports.addResolveAlias = addResolveAlias;
22
32
  const removeResolveAlias = (name) => {
23
33
  const modulePath = require.resolve(name);
24
- if (!RESOLVER_MAP[modulePath]) {
34
+ if (!(modulePath in RESOLVER_MAP)) {
25
35
  return;
26
36
  }
27
37
  const m = require.cache[modulePath];
28
38
  if (!m) {
29
39
  throw new Error("Failed to resolve webpack-dev-server");
30
40
  }
31
- if (RESOLVER_MAP[modulePath]) {
32
- m.require.resolve = RESOLVER_MAP[modulePath];
33
- delete RESOLVER_MAP[modulePath];
34
- }
41
+ Module._resolveFilename = MODULE_MAP[modulePath];
42
+ m.require.resolve = RESOLVER_MAP[modulePath];
43
+ delete RESOLVER_MAP[modulePath];
35
44
  };
36
45
  exports.removeResolveAlias = removeResolveAlias;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@rspack/dev-server",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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
- "@rspack/core": "1.0.6",
52
- "@rspack/dev-server": "1.0.6"
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 -w -b ./tsconfig.build.json",
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 ../../node_modules/jest-cli/bin/jest --colors",
73
- "api-extractor": "api-extractor run --verbose",
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
  }