// Dev server. Serves the reference SoundFont (GeneralUser GS by default, or $REF_SF2) at /ref.sf2 // so the app can A/B against it without uploading it; the file never leaves this machine. import { defineConfig, type Plugin } from "vite"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; const REF = process.env.REF_SF2 ?? path.join(os.homedir(), "Downloads", "GeneralUser-GS", "GeneralUser-GS.sf2"); const refSf2: Plugin = { name: "ref-sf2", configureServer(server) { server.middlewares.use("/ref.sf2", (_req, res) => { if (!fs.existsSync(REF)) { res.statusCode = 404; res.end(`no reference SF2 at ${REF} (set REF_SF2)`); return; } res.setHeader("Content-Type", "application/octet-stream"); res.setHeader("Content-Length", String(fs.statSync(REF).size)); fs.createReadStream(REF).pipe(res); }); }, }; export default defineConfig({ // the vault's site base path (set by configure-pages in the deploy workflow), "/" locally base: process.env.MOCHI_SITE_BASE_PATH || "/", plugins: [refSf2], assetsInclude: ["**/*.sf2", "**/*.bin"], worker: { format: "es" }, build: { target: "es2022" }, });