Skip to content
Get started

Vite plugin and configuration

View as Markdown

A Minekube project is a Vite project, as a Cloudflare Workers project is with its Vite plugin. vite.config.ts says what the project builds and where it goes. mk init writes one for you.

vite.config.ts
import { minekube } from "@minekube/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
minekube({
bundles: {
arena: { platform: "paper", entry: "src/game.ts" },
lobby: { platform: "velocity", entry: "proxy/velocity.ts" },
},
paper: { version: "26.3" },
velocity: { version: "4.3.1" },
targets: {
canary: { network: "play", selector: "channel=canary" },
prod: { network: "play", selector: "*" },
},
}),
],
});
Field Required What it is
bundles Yes The bundles the project builds, by name. Nothing is built by convention.
bundles.<name>.platform Yes Where the bundle runs: paper (a game on a Paper server), velocity (a proxy bundle on the Velocity proxy) or client (a bundle in a Minecraft client, which never goes to a network).
bundles.<name>.entry Yes The module whose default export is the bundle (Paper.make, Velocity.make, Client.make), from the project folder.
paper With a paper bundle The Paper version the project’s games are built for: { version: "26.3" }, the Minecraft version as PaperMC names it, and build to pin one build of it (build: 273); without it the newest stable build. mk types generates types/paper for it, mk server runs it, and dist/minekube.json records it.
paper.plugins, velocity.plugins No The APIs of other plugins on the server the bundles call, typed with the platform: Maven artifacts, "net.luckperms:api:5.5" from Maven Central or { maven, repository }. See Other plugins’ APIs.
velocity With a velocity bundle The Velocity version the proxy bundles are built for, the same way: { version: "4.3.1" }.
targets No Where mk deploy goes, by name, like Wrangler’s environments. With one target, mk deploy needs no argument.
targets.<name>.network Yes The network’s name, as mk network create made it.
targets.<name>.selector Yes The servers the target runs on: "*" for every server of the network, or a label selector such as channel=canary.
targets.<name>.strictVersions No true refuses to deploy while a server the target picks runs another platform version than the bundles are built for, as --strict-versions does. Without it, mk deploy lists those servers and deploys.
api No The Minekube API mk deploy and dev.join talk to. By default the one on your machine (mk api, http://localhost:4776). MINEKUBE_API and --api go before it.
dev.join No A network the dev server joins when mk server starts in the project folder, as mk server --join does: players reach your local game through the network, and every save swaps it live. Without it the dev server stays on your machine.
  • A bundle’s name is its file on the server, <name>.js: lowercase letters, digits, - and _. Each bundle builds in a Vite environment of its own, minekube_<name>, so no name clashes with Vite’s own environments or those of another plugin.
  • selector is required. All servers of a network are "*", written out, so a forgotten selector never rolls out to everyone.
  • The version is per platform, not per bundle. A project’s Paper bundles share types/paper, the dev server and the servers they deploy to, so they share one Paper version. See Platform version.
  • 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 when Vite loads it, and names every field that is wrong:
minekube() in vite.config.ts: bundles.arena.platform: Expected "paper" | "velocity" | "client"
targets.prod.selector: Missing key

These fields are part of the configuration already, so nothing changes shape later, but they are not built. A command that would use one stops with not yet supported instead of ignoring it.

Field Planned
targets.<name>.hostnames, targets.<name>.domains Names under the network and your own domains. See Hostnames and custom domains.
dev.name The name of a dev instance, so several checkouts run side by side without fixed ports.
network.routes Where a player who types an address of the network lands, by hostname, each a selector. "" is the network’s own address. Without it, players enter on the servers labelled minekube.com/entry=true.
Terminal window
mk build .

mk build is vite build (bun --bun vite build runs Vite on Bun). Each bundle becomes one file in dist/, with every dependency inside, for the JavaScript engine of the Minekube plugin. Next to them, dist/minekube.json names each bundle with its platform, the platform version it is built for, its file and SHA-256, and the project’s targets. mk deploy uploads exactly what dist/ holds, each file checked against that hash: what you built and tested is what goes up.

Terminal window
mk dev .

mk dev is vite dev, after mk types: it generates the Paper and Velocity types of the versions the project names into types/, then builds every bundle, and builds again on every save of a file a bundle imports. Each build goes where its platform runs on your machine: a Paper bundle onto the dev server (mk server), a Velocity bundle onto the dev network’s proxy (mk server --network), a client bundle into the clients of the daemon (mk daemon). The runtimes swap it in while players stay connected. Dev builds go to .minekube/dev, so dist/ keeps what the last mk build made. vite dev alone does not generate types, since that takes the Java mk manages; it says when types/ or the dev server are not the version the project names.

mk dev and vite dev talk to no Minekube API. Only dev.join opts in to a real network.

Your own backend for a game, such as friends, parties or a shop, can live in the same project as a Cloudflare Worker, with Cloudflare’s Vite plugin next to minekube():

vite.config.ts
import { cloudflare } from "@cloudflare/vite-plugin";
import { issuer, minekube, type Options } from "@minekube/vite";
import { defineConfig } from "vite";
const project = {
bundles: { lobby: { platform: "paper", entry: "src/game.ts" } },
api: "https://api.minekube.com",
} satisfies Options;
export default defineConfig(({ mode }) => ({
plugins: [
cloudflare({ config: { vars: { ISSUER: issuer(project, { network: "play", mode }), AUDIENCE: "https://friends.example.workers.dev" } } }),
minekube(project),
],
}));
  • vite build builds both: the bundles into dist/ with minekube.json, then the Worker into dist/<worker>/ for wrangler deploy.
  • vite dev runs both: the Worker in workerd, as Cloudflare’s plugin does, and the bundles installed on every save. Run it with Node (bun run dev with "dev": "vite dev" in package.json): Cloudflare’s plugin cannot start workerd from Bun, so mk dev installs the bundles but leaves the Worker out.
  • issuer(options, { network, mode }) is the issuer of the network’s instance tokens at the Minekube API the project uses: MINEKUBE_API, else api, else, in the development mode only, the one on your machine. A Worker that trusts it knows which server of the network calls it. It throws in any other mode without a registry, and for a registry over plain HTTP that is not on your machine. The issuer is the registry’s origin and /n/<network>, so write the Minekube API URL as the servers’ connector.json does: localhost and 127.0.0.1 are two issuers.

The friends example is a complete project: a Worker with a Durable Object, and a lobby bundle that calls it with Effect RPC over a WebSocket.

Command Does Like
mk types Generates types/ for the platform versions the project names wrangler types
mk deploy [target] Builds, uploads dist/ as a version, deploys it to the target wrangler deploy
mk versions upload Builds and uploads without deploying wrangler versions upload
mk versions deploy <id> --target <name> Deploys an uploaded version wrangler versions deploy
mk versions list The 50 newest versions, and where each runs wrangler versions list
mk deployments list What runs where, since when, by whom wrangler deployments list
mk rollback [id] --target <name> Back to the version before, or the one named wrangler rollback
mk undeploy [target] Ends the target’s deployment; the version stays

--message and --tag describe a version. Without them, mk takes the subject of the project’s last git commit and its hash, 12 characters with -dirty for uncommitted changes. --root names the project folder when you run a command from elsewhere. mk deploy, mk versions deploy and mk rollback list the servers of the target that run another platform version than the version they deploy was built for; --strict-versions refuses then.

Each command is a call to the Minekube API, the same on your machine as on Minekube’s. Rolling out in waves (--batch) and a limit on the versions a network keeps are planned.

Was this helpful?