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 want | Template | The SDK comes from |
|---|---|---|
| A bundler (Vite, webpack, ...) | typescript | The @mugon/sdk npm package, bundled into your game |
| No build step | minimal | A 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.jsstyle 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 publishwarns if the first script ofindex.htmldoesn't contain the SDK. - Call
ctx.progress.done()when the game is playable, unless your callback returns then.
In this section
Mugon.startand the context: everything your game gets from the platform.- Loading progress: feed the loading overlay.
- The file proxy: how your game's files are loaded and cached.
- SDK versions: how the version you build with maps to the platform's behaviour.