Skip to content

Commit

Permalink
feat: support rspack (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Nov 6, 2024
1 parent 1d99de1 commit 90b2dce
Show file tree
Hide file tree
Showing 11 changed files with 2,035 additions and 34 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://webpack.js.org/">
<img width="200" height="200" hspace="25" src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon-square-big.svg">
</a>
<p>Elegant ProgressBar and Profiler for Webpack</p>
<p>Elegant ProgressBar and Profiler for [Webpack](https://webpack.js.org/) and [Rspack](https://rspack.dev/). </p>
</div>

✔ Display elegant progress bar while building or watch
Expand Down Expand Up @@ -68,9 +68,9 @@ deno install webpackbar

<!-- /automd -->

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

**webpack.config.mjs**
**`webpack.config.mjs`**

```js
import WebpackBar from "webpackbar";
Expand All @@ -85,6 +85,23 @@ export default {
};
```

For using with [Rspack](https://rspack.dev/), you can use `webpackbar/rspack` (make sure `@rspack/core` peer dependency is installed).

**`rspack.config.mjs`**:

```js
import WebpackBar from "webpackbar/rspack";

export default {
entry: "./src/entry.js",
plugins: [
new WebpackBar({
/* options */
}),
],
};
```

<h2 align="center">Options</h2>

### `name`
Expand Down
2 changes: 1 addition & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default defineBuildConfig({
emitCJS: true,
inlineDependencies: true,
},
entries: ["src/index"],
entries: ["src/webpack", "src/rspack"],
externals: ["webpack"],
});
44 changes: 34 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
{
"name": "webpackbar",
"version": "6.0.1",
"description": "Elegant ProgressBar and Profiler for Webpack",
"description": "Elegant ProgressBar and Profiler for Webpack and Rspack",
"repository": "unjs/webpackbar",
"license": "MIT",
"type": "module",
"exports": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
".": {
"import": {
"types": "./dist/webpack.d.mts",
"default": "./dist/webpack.mjs"
},
"require": {
"types": "./dist/webpack.d.cts",
"default": "./dist/webpack.cjs"
}
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
"./rspack": {
"import": {
"types": "./dist/rspack.d.mts",
"default": "./dist/rspack.mjs"
},
"require": {
"types": "./dist/rspack.d.cts",
"default": "./dist/rspack.cjs"
}
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"main": "./dist/webpack.cjs",
"types": "./dist/webpack.d.cts",
"files": [
"dist"
],
Expand All @@ -26,6 +38,7 @@
"lint:fix": "eslint --fix . && prettier -w .",
"prepack": "unbuild",
"play": "webpack --config ./playground/webpack.config.mjs",
"play:rspack": "rspack --config ./playground/rspack.config.mjs",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && vitest run"
},
Expand All @@ -37,6 +50,8 @@
},
"devDependencies": {
"@babel/standalone": "^7.26.2",
"@rspack/cli": "^1.0.14",
"@rspack/core": "^1.0.14",
"@types/node": "^22.9.0",
"automd": "^0.3.12",
"chalk": "^5.3.0",
Expand All @@ -56,7 +71,16 @@
"wrap-ansi": "^9.0.0"
},
"peerDependencies": {
"webpack": "3 || 4 || 5"
"webpack": "3 || 4 || 5",
"@rspack/core": "*"
},
"peerDependenciesMeta": {
"webpack": {
"optional": true
},
"@rspack/core": {
"optional": true
}
},
"packageManager": "[email protected]",
"engines": {
Expand Down
45 changes: 45 additions & 0 deletions playground/rspack.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import WebpackBar from "webpackbar/rspack";

// let lastProgress;

const __dirname = dirname(fileURLToPath(import.meta.url));

const config = (name, color) => ({
mode: "production",
context: __dirname,
devtool: false,
target: "node",
entry: `./${name}.mjs`,
stats: true,
output: {
filename: "./output.cjs",
path: join(__dirname, "/dist"),
},
module: {
rules: [{ test: /\.js$/, use: join(__dirname, "test-loader.cjs") }],
},
plugins: [
new WebpackBar({
color,
name,
reporters: ["fancy"],
profile: process.argv.includes("--profile"),
// reporter: {
// progress ({ state }) {
// if (lastProgress !== state.progress && state.progress % 5 === 0) {
// process.stderr.write(state.progress + '%\n')
// lastProgress = state.progress
// }
// }
// }
}),
],
});

setInterval(() => {
console.log(`[${new Date().toLocaleTimeString()}]`);
}, 1000).unref();

export default [config("chalk", "cyan"), config("babel", "yellow")];
Loading

0 comments on commit 90b2dce

Please sign in to comment.