/ music / acoustic-base
Sign in
music / acoustic-base
acoustic-base / vite.config.ts
29 lines · 1.1 KBBlameHistoryRaw
1// Dev server. Serves the reference SoundFont (GeneralUser GS by default, or $REF_SF2) at /ref.sf2
2// so the app can A/B against it without uploading it; the file never leaves this machine.
3import { defineConfig, type Plugin } from "vite";
4import fs from "node:fs";
5import os from "node:os";
6import path from "node:path";
8const REF = process.env.REF_SF2 ?? path.join(os.homedir(), "Downloads", "GeneralUser-GS", "GeneralUser-GS.sf2");
10const refSf2: Plugin = {
11 name: "ref-sf2",
12 configureServer(server) {
13 server.middlewares.use("/ref.sf2", (_req, res) => {
14 if (!fs.existsSync(REF)) { res.statusCode = 404; res.end(`no reference SF2 at ${REF} (set REF_SF2)`); return; }
15 res.setHeader("Content-Type", "application/octet-stream");
16 res.setHeader("Content-Length", String(fs.statSync(REF).size));
17 fs.createReadStream(REF).pipe(res);
18 });
19 },
20};
22export default defineConfig({
23 // the vault's site base path (set by configure-pages in the deploy workflow), "/" locally
24 base: process.env.MOCHI_SITE_BASE_PATH || "/",
25 plugins: [refSf2],
26 assetsInclude: ["**/*.sf2"],
27 worker: { format: "es" },
28 build: { target: "es2022" },
29});
↑↓ move↵openescclose