# Rollup

Build every package with a Rollup config, with the bundle cached.

The Rollup plugin gives every package with a Rollup config a `build` task.

## Add it

```sh
axle add rollup
```

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

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

## Tasks

A package or project with a `rollup.config.js`, `.mjs` or `.cjs` in its folder gets:

| Task    | Command           | Settings                            |
| ------- | ----------------- | ----------------------------------- |
| `build` | `rollup --config` | `outputs` the output folder or file |

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

The outputs are read from the config without running it: `output.dir` as a folder and `output.file` as a file, so a config with one of each has both. When either is set to something other than a plain string, or to different values in different outputs, the plugin leaves `outputs` out and Axle [finds the outputs](https://axlers.dev/docs/reference/cache.md#outputs) the build writes itself. A config in TypeScript needs a script, since Rollup needs a plugin to read it.

## 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": "rollup -c --environment BUILD:production"`, the plugin leaves that task alone and Axle runs the script. A script that only runs the same command, `rollup --config` or `rollup -c`, is replaced by the plugin's task, which runs the same command and adds its settings. 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 |

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

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