mugon.net docs
SDKsJavaScript

JavaScript

Games written in TypeScript or JavaScript, with or without a bundler.

The JavaScript SDK is @mugon/sdk. It is what every other SDK builds on, and it works on its own for games written in TypeScript or JavaScript.

You wantTemplateThe SDK comes from
A bundler (Vite, webpack, ...)typescriptThe @mugon/sdk npm package, bundled into your game
No build stepminimalA mugon.iife.js script that the template ships in your distribution folder

With a bundler

The typescript template is a Vite project. The relevant parts:

// src/index.ts -- the SDK must be imported first
import { Mugon } from "@mugon/sdk";

Mugon.start(async (ctx) => {
  ctx.on("connect", (peerId) => console.log("peer connected", peerId));
  // ... create your game, then:
  ctx.progress.done();
});
// package.json
"scripts": { "build": "vite build --base ./ --outDir dist" }

Without a bundler

The minimal template has a plain index.html and script. The SDK is loaded as the first script, which makes the global Mugon available:

<script src="./mugon.iife.js"></script>
<script src="./index.js"></script>

Things to get right

  • Build with a relative base (--base ./). The platform serves your game from a folder, not from the root of a domain, so /assets/x.js style absolute URLs won't resolve.
  • Keep the SDK first. If your bundler splits chunks, the entry chunk must contain the SDK import before anything that loads big files. mugon publish warns if the first script of index.html doesn't contain the SDK.
  • Call ctx.progress.done() when the game is playable, unless your callback returns then.

In this section

On this page