# Vite plugin and configuration

> Planned: a project declares its bundles and its targets in vite.config.ts, one core serves the Vite plugin and the mk CLI, and commands named as in Wrangler replace mk publish.

> **Planned:**
> This page describes a design that is not built yet. Today you publish with `mk publish`, `mk revisions` and `mk unpublish`; see [Publish a revision](https://minekube.com/games/versions-and-deployments/publish).

Today, `mk dev` and `mk publish` find a game by convention: `src/game.ts` and `network/velocity.ts`. The plan is one configuration that says what a project builds and where it goes, like a Cloudflare Workers project with its Vite plugin and Wrangler.

## The configuration

```ts title="vite.config.ts"

export default defineConfig({
  plugins: [
    minekube({
      bundles: {
        arena: { platform: "paper", entry: "src/game.ts" },
        lobby: { platform: "velocity", entry: "network/velocity.ts" },
      },
      targets: {
        canary: { network: "play", selector: "channel=canary" },
        prod: {
          network: "play",
          selector: "*",
          hostnames: ["arena"],
          domains: ["arena.example.com"],
        },
      },
    }),
  ],
});
```

- **`bundles` is required.** Nothing is built by convention. Name, platform and entry are explicit, and a project can have several bundles per platform.
- **`targets` are where `mk deploy` goes**, like Wrangler's environments. With one target, `mk deploy` needs no argument.
- **`selector` is required.** All servers of a network are `"*"`, written out, so a forgotten selector never rolls out to everyone.
- **There are no build commands.** The build is Vite itself. An extra step is a Vite plugin or a script in `package.json`.
- **The plugin checks the configuration** with an Effect Schema and names the field that is wrong.

## One core for the plugin and the CLI

The Vite plugin and `mk` share one core: read and check the configuration, build, run the dev server, install and upload. `mk dev`, `mk build` and `mk deploy` call the same functions as `vite dev` and `vite build`. Paper and Velocity become environments of Vite's Environment API, as Cloudflare's plugin runs `workerd`. Bun stays the runtime, package manager and test runner.

`vite build` writes `dist/` with the bundles and a `minekube.json` that names each bundle with its platform and SHA-256. What you tested is what you upload.

## Commands

| Today | Planned | Like |
| --- | --- | --- |
| `mk publish` | `mk deploy [target]`: build, upload, assign | `wrangler deploy` |
| | `mk versions upload`: upload without assigning | `wrangler versions upload` |
| | `mk versions deploy <id> [--batch 20%]` | `wrangler versions deploy` |
| `mk revisions` | `mk versions list`, `mk deployments list` | `wrangler versions list`, `deployments list` |
| `mk publish --revision` | `mk rollback [id]` | `wrangler rollback` |
| `mk unpublish` | `mk undeploy [target]` | |

`--message` and `--tag` describe a version. Without them, `mk deploy` takes the commit message and hash from git. The network keeps the last 100 versions and every version that is assigned.

## Related

- [Controlled updates](https://minekube.com/games/versions-and-deployments/controlled-updates): waves, and games that hold an update until a round ends.
- [Hostnames and custom domains](https://minekube.com/games/versions-and-deployments/hostnames): the `hostnames` and `domains` of a target.
