import { readFileSync } from "node:fs"; import path from "node:path"; import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; // @ts-expect-error Shared Node HTTP middleware also serves production bundles. import { createBundledContentHandler } from "./server/bundled-content.mjs"; const packageVersion = (JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as { version: string }).version; export default defineConfig(({ mode }) => { const androidBuild = mode === "android"; const downloadableBuild = androidBuild || mode === "production"; return { plugins: [react(), { name: "bundled-content-preview", configurePreviewServer(server) { const serve = createBundledContentHandler(path.resolve(androidBuild ? "dist-android" : "dist")); server.middlewares.use((request, response, next) => { if (!serve(request, response, new URL(request.url ?? "/", "http://localhost").pathname)) next(); }); }, }], publicDir: androidBuild ? ".android-public" : downloadableBuild ? ".web-public" : "public", define: { "import.meta.env.VITE_APP_VERSION": JSON.stringify(packageVersion), "import.meta.env.VITE_CONTENT_MODE": JSON.stringify(downloadableBuild ? "downloadable" : "bundled"), }, resolve: { alias: { "@dungeonAssetModules": path.resolve( downloadableBuild ? "src/game/dungeonAssetModules.android.ts" : "src/game/dungeonAssetModules.ts", ), }, }, server: { proxy: { "/api": "http://127.0.0.1:4173", "/content": "http://127.0.0.1:4173", }, watch: { // Asset-pipeline staging files are large, short-lived, and can be locked // while iCloud or conversion tools are writing them. They are not app // source, so watching them only risks taking the dev server down with // EBUSY on Windows. ignored: [ "**/dungeon-pipeline/**", "**/playtest-artifacts/**", ], }, }, build: { target: "es2022", sourcemap: false, emptyOutDir: true, outDir: androidBuild ? "dist-android" : "dist", }, test: { environment: "node", include: ["src/**/*.test.ts"], }, }; });