# React Router

Build, serve, start and type-check every React Router app, with the build output cached.

The React Router plugin gives every app in React Router's framework mode a `build`, `dev`, `start` and `typecheck` task, so a repository of React Router apps builds, caches and serves them without a script for each.

## Add it

```sh
axle add react-router
```

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

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

## Tasks

A package or project with a `react-router.config` file, `.ts` or another config extension, in its folder gets:

| Task        | Command                                      | Settings                                                       |
| ----------- | -------------------------------------------- | -------------------------------------------------------------- |
| `build`     | `react-router build`                         | `outputs` `build`                                              |
| `dev`       | `react-router dev`                           | `persistent`, ready when the server prints its `Local` address |
| `start`     | `react-router-serve ./build/server/index.js` | `persistent`, after the `build`                                |
| `typecheck` | `react-router typegen && tsc`                | `outputs` the types it generates in `.react-router`            |

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

The [Vite plugin](https://axlers.dev/docs/official-plugins/vite.md) leaves React Router apps to this one, so the two can be added together. An app with its own server, such as an Express one, keeps its own `start` script.

## 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 `"start": "node server.js"`, the plugin leaves that task alone and Axle runs the script. A script that runs the same command is replaced by the plugin's task, which runs it 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 |
| `dev`       | `"dev"`       | the name of the dev server task, or `false`            |
| `start`     | `"start"`     | the name of the task that serves the build, or `false` |
| `typecheck` | `"typecheck"` | the name of the type-check task, or `false`            |

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