From 59d841aaf1181da95a1056c362fae271c23ebaa9 Mon Sep 17 00:00:00 2001 From: tfrere Date: Thu, 10 Sep 2026 08:33:02 +0200 Subject: [PATCH] fix(build): configurable base prefix and relative mesh_dir for /play/ hosting Co-authored-by: Cursor --- app/src/game/duck.js | 6 ++++++ app/vite.config.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/src/game/duck.js b/app/src/game/duck.js index c69126f..be90213 100644 --- a/app/src/game/duck.js +++ b/app/src/game/duck.js @@ -35,6 +35,12 @@ export async function loadKinematics(url) { const r = await fetch(signed(`${url}?v=${MESH_VERSION}`), { cache: "force-cache" }); if (!r.ok) throw new Error(`kinematics fetch ${r.status}`); const k = await r.json(); + // The exported mesh_dir is root-absolute ("/robot/mjlab/meshes"), which + // breaks when the app is served under a prefix (/play/). Rebase it like + // every other asset URL (MODEL_DIR is "./robot/mjlab"). + if (typeof k.mesh_dir === "string" && k.mesh_dir.startsWith("/")) { + k.mesh_dir = `.${k.mesh_dir}`; + } // Full-resolution meshes by default (the reduction will be redone // interactively in Blender later). `?lite=1` opts into a decimated // meshes-lite/ sibling if present. diff --git a/app/vite.config.js b/app/vite.config.js index bcafbe2..1cd9534 100644 --- a/app/vite.config.js +++ b/app/vite.config.js @@ -2,6 +2,11 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; export default defineConfig({ + // Deploy prefix: "/" standalone (the HF Space), "/play/" when the bundle + // is served under the Microduck Academy (VITE_BASE=/play/ npm run build). + // Runtime asset URLs are base-relative ("./assets", "./policies") so + // only the bundle references in index.html depend on this. + base: process.env.VITE_BASE || "/", plugins: [react()], // MuJoCo WASM and onnxruntime-web stay on the CDN (dynamic import with // @vite-ignore in game/boot.js), exactly like the pre-Vite app: their