rune-sdk
Version:
Build a multiplayer game played by millions! Your game runs inside the Rune app with 10 million installs across [iOS](https://apps.apple.com/app/rune-games-and-voice-chat/id1450358364) and [Android](https://play.google.com/store/apps/details?id=ai.rune.ti
59 lines (58 loc) • 2.28 kB
JavaScript
import { readFileSync } from "node:fs";
import path from "node:path";
import crypto from "crypto";
const runtimePublicPath = "/@rune-sdk";
export function getDevPlugins(runePkgPath) {
return [
{
name: "vite:rune-plugin:resolve-runtime",
apply: "serve",
enforce: "pre",
resolveId: (id) => (id === runtimePublicPath ? id : undefined),
load: (id) => id === runtimePublicPath
? readFileSync(path.resolve(runePkgPath, "../multiplayer-dev.js"), "utf-8")
: undefined,
},
{
name: "vite:rune-plugin:inject-runtime",
apply: "serve",
enforce: "post",
transformIndexHtml(html) {
return {
html,
tags: [
{
tag: "style",
children: `html, body { background-color: #1c002b; }`,
attrs: {
id: "sdk-load-styles",
"data-background-color": "1",
},
injectTo: "head-prepend",
},
// Inject a tag to differentiate between different games when running in dev mode
{
tag: "script",
attrs: {
id: "sdk-settings",
"data-rune-allow-before-sdk": "1",
},
children: `window.__SDK_SETTINGS_ID__='${crypto
.createHash("shake256", { outputLength: 8 })
.update(process.cwd())
.digest("hex")}'`,
injectTo: "head-prepend",
},
{
tag: "script",
attrs: {
src: runtimePublicPath,
},
injectTo: "head-prepend",
},
],
};
},
},
];
}