# SvelteKit

Build, serve, preview and check every SvelteKit app, with the build output cached.

The SvelteKit plugin gives every SvelteKit app a `build`, `dev`, `preview` and `check` task, so a repository of SvelteKit apps builds, caches, serves and checks them without a script for each.

## Add it

```sh
axle add sveltekit
```

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

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

## Tasks

A package or project with a `svelte.config` file, `.js`, `.ts` or another config extension, and `@sveltejs/kit` among its dependencies gets:

| Task      | Command                                                      | Settings                                                 |
| --------- | ------------------------------------------------------------ | -------------------------------------------------------- |
| `build`   | `vite build`                                                 | `outputs` `.svelte-kit/output` and `build`               |
| `dev`     | `vite dev`                                                   | `persistent`, ready when Vite prints its `Local` address |
| `preview` | `vite preview`                                               | `persistent`, after the `build`                          |
| `check`   | `svelte-kit sync && svelte-check --tsconfig ./tsconfig.json` | `outputs` nothing                                        |

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

`build` is where `adapter-node` and `adapter-static` write. Another adapter that writes elsewhere needs `outputs` set for `build` in the package's `axle.toml`. The [Vite plugin](https://axlers.dev/docs/official-plugins/vite.md) leaves SvelteKit apps to this one, so the two can be added together.

## 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 `"dev": "vite dev --host"`, 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`            |
| `preview` | `"preview"` | the name of the preview task, or `false`               |
| `check`   | `"check"`   | the name of the check task, or `false`                 |

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