コンテンツにスキップ

Add a game

このコンテンツはまだ日本語訳がありません。

Each game is a static page in games/<folder> of the chatbotgang/mini-games repository.

  1. Create games/<folder> with index.html, src/main.ts, a vite.config.ts that sets base: "./", and a package.json whose miniGame field names the game:

    "miniGame": {
    "id": "my-game",
    "title": { "zh-TW": "…", "en": "…", "ja": "…", "th": "…" }
    }
  2. Connect to the host with @mini-games/game-kit:

    import { connectHost } from "@mini-games/game-kit";
    const host = connectHost(); // applies theme and lang to <html>
    host.onConfig((config) => redraw(config));
    host.onPause((paused) => (paused ? stop() : start()));
    // After the first frame is drawn:
    host.ready();
  3. Keep the game logic in pure functions with Vitest tests, and the canvas or DOM code apart.

  4. Add the game’s JS to .size-limit.json with a 15 kB gzip limit.

  5. Add the game to the site’s devDependencies in apps/web/package.json, and add a page for it in each language under apps/web/src/content/docs/**/games/.

  6. Add a changeset for @mini-games/web so the next release deploys it.

pnpm dev builds the games, copies them under /v1/ and starts the site.