# Rsbuild

Build, serve and preview every package with an Rsbuild config.

The Rsbuild plugin gives every package with an Rsbuild config a `build` task, and `dev` and `preview` tasks that keep running.

## Add it

```sh
axle add rsbuild
```

This writes it into the root `axle.toml`:

```toml
[plugins.rsbuild]
source = "npm:@axle-rs/plugin-rsbuild@0.1.0"
hash = "sha256-…"
```

## Tasks

A package or project with an `rsbuild.config` file, `.ts`, `.mts`, `.cts`, `.js`, `.mjs` or `.cjs`, in its folder gets:

| Task      | Command           | Settings                                                       |
| --------- | ----------------- | -------------------------------------------------------------- |
| `build`   | `rsbuild build`   | `outputs` the output folder, `dist` unless the config moves it |
| `dev`     | `rsbuild dev`     | `persistent`, ready when Rsbuild prints its `Local` address    |
| `preview` | `rsbuild preview` | `persistent`, after `build`, ready the same way                |

Each command runs through the repository's package manager, such as `pnpm exec rsbuild build`, so it uses the version the package installs.

The output folder is read from the config without running it: `output.distPath.root` when it's a plain string, and `dist` when the config doesn't set `distPath`. A `distPath` without a `root`, or with a `root` that isn't a plain string, and a top-level `root` that moves the project, leave `outputs` out, and Axle [finds the outputs](https://axlers.dev/docs/reference/cache.md#outputs) the build writes itself.

## Scripts the repository already has

A package's own script wins. When its `package.json` has a script with a task's name that runs something else, such as `"build": "rsbuild build --env-mode staging"`, the plugin leaves that task alone and Axle runs the script. A script that only runs the same command is replaced by the plugin's task, which runs the same command and adds its settings; for `dev`, that's `rsbuild dev` or `rsbuild`. The repository's `axle.toml` changes a task as it would any other, and wins over the plugin.

## Settings

| Setting   | Default     | Meaning                                                |
| --------- | ----------- | ------------------------------------------------------ |
| `build`   | `"build"`   | the name of the build task, or `false` to leave it out |
| `dev`     | `"dev"`     | the name of the dev server task, or `false`            |
| `preview` | `"preview"` | the name of the preview task, or `false`               |

The plugin's answers are kept until an `rsbuild.config.*`, a `package.json`, `pnpm-workspace.yaml` or a lockfile changes.
