1import { defineConfig } from "vite";
3// One multi-page site: src/index.html (landing page) and one page per app in
4// src/<app>/index.html, served at /<app>/. Shared code goes in src/common/.
5// Relative asset paths, so the build works wherever the site is served
6// (an origin root or a /<collection>/<repo>/site/ path); ES module workers.
7const page = (p: string) => decodeURIComponent(new URL(`./src/${p}`, import.meta.url).pathname);
9export default defineConfig({
10 root: "src",
11 base: "./",
12 worker: { format: "es" },
13 build: {
14 outDir: "../dist",
15 emptyOutDir: true,
16 rolldownOptions: {
17 input: {
18 main: page("index.html"),
19 "double-pendulum": page("double-pendulum/index.html"),
20 "fput-chain": page("fput-chain/index.html"),
21 beam: page("beam/index.html"),
22 plate: page("plate/index.html"),
23 "driven-plate": page("driven-plate/index.html"),
24 },
25 // Name the chunk holding src/common/ "common" (otherwise it takes the
26 // name of one of its modules).
27 output: { manualChunks: (id: string) => (id.includes("/src/common/") ? "common" : undefined) },
28 },
29 },
30});