Skip to content

Commit 90b2dce

Browse files
authored
feat: support rspack (#149)
1 parent 1d99de1 commit 90b2dce

11 files changed

+2035
-34
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<a href="https://webpack.js.org/">
1212
<img width="200" height="200" hspace="25" src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon-square-big.svg">
1313
</a>
14-
<p>Elegant ProgressBar and Profiler for Webpack</p>
14+
<p>Elegant ProgressBar and Profiler for [Webpack](https://webpack.js.org/) and [Rspack](https://rspack.dev/). </p>
1515
</div>
1616

1717
✔ Display elegant progress bar while building or watch
@@ -68,9 +68,9 @@ deno install webpackbar
6868

6969
<!-- /automd -->
7070

71-
Then add the reporter as a plugin to your webpack config.
71+
Then add the reporter as a plugin to your webpack config (make sure `webpack` peer dependency is installed).
7272

73-
**webpack.config.mjs**
73+
**`webpack.config.mjs`**
7474

7575
```js
7676
import WebpackBar from "webpackbar";
@@ -85,6 +85,23 @@ export default {
8585
};
8686
```
8787

88+
For using with [Rspack](https://rspack.dev/), you can use `webpackbar/rspack` (make sure `@rspack/core` peer dependency is installed).
89+
90+
**`rspack.config.mjs`**:
91+
92+
```js
93+
import WebpackBar from "webpackbar/rspack";
94+
95+
export default {
96+
entry: "./src/entry.js",
97+
plugins: [
98+
new WebpackBar({
99+
/* options */
100+
}),
101+
],
102+
};
103+
```
104+
88105
<h2 align="center">Options</h2>
89106

90107
### `name`

build.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export default defineBuildConfig({
66
emitCJS: true,
77
inlineDependencies: true,
88
},
9-
entries: ["src/index"],
9+
entries: ["src/webpack", "src/rspack"],
1010
externals: ["webpack"],
1111
});

package.json

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
{
22
"name": "webpackbar",
33
"version": "6.0.1",
4-
"description": "Elegant ProgressBar and Profiler for Webpack",
4+
"description": "Elegant ProgressBar and Profiler for Webpack and Rspack",
55
"repository": "unjs/webpackbar",
66
"license": "MIT",
77
"type": "module",
88
"exports": {
9-
"import": {
10-
"types": "./dist/index.d.mts",
11-
"default": "./dist/index.mjs"
9+
".": {
10+
"import": {
11+
"types": "./dist/webpack.d.mts",
12+
"default": "./dist/webpack.mjs"
13+
},
14+
"require": {
15+
"types": "./dist/webpack.d.cts",
16+
"default": "./dist/webpack.cjs"
17+
}
1218
},
13-
"require": {
14-
"types": "./dist/index.d.cts",
15-
"default": "./dist/index.cjs"
19+
"./rspack": {
20+
"import": {
21+
"types": "./dist/rspack.d.mts",
22+
"default": "./dist/rspack.mjs"
23+
},
24+
"require": {
25+
"types": "./dist/rspack.d.cts",
26+
"default": "./dist/rspack.cjs"
27+
}
1628
}
1729
},
18-
"main": "./dist/index.cjs",
19-
"types": "./dist/index.d.ts",
30+
"main": "./dist/webpack.cjs",
31+
"types": "./dist/webpack.d.cts",
2032
"files": [
2133
"dist"
2234
],
@@ -26,6 +38,7 @@
2638
"lint:fix": "eslint --fix . && prettier -w .",
2739
"prepack": "unbuild",
2840
"play": "webpack --config ./playground/webpack.config.mjs",
41+
"play:rspack": "rspack --config ./playground/rspack.config.mjs",
2942
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
3043
"test": "pnpm lint && vitest run"
3144
},
@@ -37,6 +50,8 @@
3750
},
3851
"devDependencies": {
3952
"@babel/standalone": "^7.26.2",
53+
"@rspack/cli": "^1.0.14",
54+
"@rspack/core": "^1.0.14",
4055
"@types/node": "^22.9.0",
4156
"automd": "^0.3.12",
4257
"chalk": "^5.3.0",
@@ -56,7 +71,16 @@
5671
"wrap-ansi": "^9.0.0"
5772
},
5873
"peerDependencies": {
59-
"webpack": "3 || 4 || 5"
74+
"webpack": "3 || 4 || 5",
75+
"@rspack/core": "*"
76+
},
77+
"peerDependenciesMeta": {
78+
"webpack": {
79+
"optional": true
80+
},
81+
"@rspack/core": {
82+
"optional": true
83+
}
6084
},
6185
"packageManager": "pnpm@9.12.3",
6286
"engines": {

playground/rspack.config.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { dirname, join } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import WebpackBar from "webpackbar/rspack";
4+
5+
// let lastProgress;
6+
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
8+
9+
const config = (name, color) => ({
10+
mode: "production",
11+
context: __dirname,
12+
devtool: false,
13+
target: "node",
14+
entry: `./${name}.mjs`,
15+
stats: true,
16+
output: {
17+
filename: "./output.cjs",
18+
path: join(__dirname, "/dist"),
19+
},
20+
module: {
21+
rules: [{ test: /\.js$/, use: join(__dirname, "test-loader.cjs") }],
22+
},
23+
plugins: [
24+
new WebpackBar({
25+
color,
26+
name,
27+
reporters: ["fancy"],
28+
profile: process.argv.includes("--profile"),
29+
// reporter: {
30+
// progress ({ state }) {
31+
// if (lastProgress !== state.progress && state.progress % 5 === 0) {
32+
// process.stderr.write(state.progress + '%\n')
33+
// lastProgress = state.progress
34+
// }
35+
// }
36+
// }
37+
}),
38+
],
39+
});
40+
41+
setInterval(() => {
42+
console.log(`[${new Date().toLocaleTimeString()}]`);
43+
}, 1000).unref();
44+
45+
export default [config("chalk", "cyan"), config("babel", "yellow")];

0 commit comments

Comments
 (0)