Skip to content

Commit

Permalink
doc: how to create a addon
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz committed Oct 25, 2023
1 parent f906ca4 commit 1744a17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,11 @@ interface Addon {
2. move the project dependencies to global package.json
3. add `rspack.config.js` to make the project runnable by rspack
4. add `hmr.js` to make the project support hmr changes
5. try run `node bin/bench.js <your case>_<your addons>` to test
5. try run `RSPACK_CLI_BIN=<your-rspack-cli> node bin/bench.js <your case>_<your addons>` to test

## How to create a addon

1. create your addons in `/lib/addons` with kebab case like "a-b-c.js"
2. export default a class that extends `/lib/addons/common` and implement the hooks you want to listen
3. try run `RSPACK_CLI_BIN=<your-rspack-cli> node bin/bench.js <case>_<your addons>` to test
4. if you want to run some benchmarkName by default, you can add it to `defaultBenchmarkNames` in `/bin/bench.js`
21 changes: 11 additions & 10 deletions bin/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import { run, formatResultTable } from "../lib/index.js";
const [, , ...benchmarkNames] = process.argv;

const rootDir = resolve(fileURLToPath(import.meta.url), "../..");
const defaultBenchmarkNames = [
"10000_development-mode",
"10000_development-mode_hmr",
"10000_production-mode",
"10000_production-mode_builtin-swc-loader",
"threejs_development-mode_10x",
"threejs_development-mode_10x_hmr",
"threejs_production-mode_10x",
"threejs_production-mode_builtin-swc-loader_10x"
];

(async () => {
await mkdir(resolve(rootDir, "output"), { recursive: true });
const benchmarks = benchmarkNames.length
? benchmarkNames
: [
"10000_development-mode",
"10000_development-mode_hmr",
"10000_production-mode",
"10000_production-mode_builtin-swc-loader",
"threejs_development-mode_10x",
"threejs_development-mode_10x_hmr",
"threejs_production-mode_10x",
"threejs_production-mode_builtin-swc-loader_10x"
];
: defaultBenchmarkNames;
for (const item of benchmarks) {
const result = await run(item);
console.log(`${item} result is:`);
Expand Down

0 comments on commit 1744a17

Please sign in to comment.