Skip to content

Commit

Permalink
feat: create rspack softlink in node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz committed Nov 23, 2023
1 parent c0daaf6 commit 7b3bb85
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ node bin/build-rspack.js origin pull/1000/head # use the pull request with index

* `node bin/bench.js [benchmarkNames...]`

Run benchmark with rspack and write the output to `output` folder. You can configure the environment variable of `RSPACK_CLI_BIN` to set the rspack command path, and it will use the rspack from the `.rspack` folder by default. eg.
Run benchmark with rspack and write the output to `output` folder. You can configure the environment variable of `RSPACK_DIR` to set the rspack project path, and it will use the rspack from the `.rspack` folder by default. eg.

``` bash
node bin/bench.js # run all benchmarks
node bin/bench.js 10000_development-mode 10000_production-mode # run benchmarks named 10000_development-mode and 10000_production-mode
RSPACK_CLI_BIN=<your-rspack-cli> node bin/bench.js 10000_development-mode_hmr # set the rspack command path, and run 10000_development-mode_hmr
RSPACK_DIR=<your-rspack-path> node bin/bench.js 10000_development-mode_hmr # set the rspack command path, and run 10000_development-mode_hmr
```

* `node bin/compare-bench.js <baseDate> <currentDate>`
Expand Down Expand Up @@ -163,11 +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 `RSPACK_CLI_BIN=<your-rspack-cli> node bin/bench.js <your case>_<your addons>` to test
5. try run `RSPACK_DIR=<your-rspack-path> 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
3. try run `RSPACK_DIR=<your-rspack-path> 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`
10 changes: 7 additions & 3 deletions cases/10000/rspack.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const path = require("path");
const rspack = require("@rspack/core");

/** @type {import("@rspack/cli").Configuration} */
module.exports = {
resolve: {
extensions: [".js", ".jsx"]
},
entry: { main: "./index.jsx" },
builtins: {
html: [{ template: path.resolve(__dirname, "./index.html") }]
},
plugins: [
new rspack.HtmlRspackPlugin({
template: path.resolve(__dirname, "./index.html")
})
],
optimization: {
splitChunks: {
chunks: "all",
Expand Down
16 changes: 14 additions & 2 deletions lib/scenarios/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ async function runRspack(ctx) {
};
let remainingLine = "";
await runCommand(
process.env.RSPACK_CLI_BIN ||
path.resolve(rootDir, ".rspack/packages/rspack-cli/bin/rspack"),
path.resolve(rootDir, "./node_modules/@rspack/cli/bin/rspack"),
ctx.rspackArgs,
{
verbose: false,
Expand Down Expand Up @@ -100,6 +99,19 @@ module.exports.plugins.push(new (require("../../lib/scenarios/build-plugin.cjs")
path.resolve(ctx.caseDir, "rspack.config.js"),
ctx.config
);
const rspackDir =
process.env.RSPACK_DIR || path.resolve(rootDir, ".rspack");
console.log("create rspack package link");
await runCommand("ln", [
"-nsf",
path.resolve(rspackDir, "packages/rspack"),
path.resolve(rootDir, "node_modules/@rspack/core")
]);
await runCommand("ln", [
"-nsf",
path.resolve(rspackDir, "packages/rspack-cli"),
path.resolve(rootDir, "node_modules/@rspack/cli")
]);
},
async warmup(ctx) {
console.log("run rspack with args:", ctx.rspackArgs);
Expand Down

0 comments on commit 7b3bb85

Please sign in to comment.