import fs from "node:fs"; import path from "node:path"; import { defineConfig } from "vitest/config"; import { VitePWA } from "vite-plugin-pwa"; /** Drop the previous app build. Kacheln, icons, and the Übersicht stay. */ function replaceGeneratedApp() { return { name: "replace-generated-app", apply: "build" as const, buildStart() { const outDir = path.resolve("public"); fs.rmSync(path.join(outDir, "assets"), { recursive: true, force: true }); for (const name of ["index.html", "sw.js", "manifest.webmanifest"]) { fs.rmSync(path.join(outDir, name), { force: true }); } if (!fs.existsSync(outDir)) return; for (const name of fs.readdirSync(outDir)) { if (name.startsWith("workbox-") && name.endsWith(".js")) { fs.rmSync(path.join(outDir, name)); } } }, }; } export default defineConfig({ plugins: [ replaceGeneratedApp(), VitePWA({ registerType: "autoUpdate", includeAssets: ["icon-192.png", "icon-512.png", "uebersicht.json"], manifest: { name: "Karte", short_name: "Karte", description: "DTK25-Karte für das Gelände", lang: "de", start_url: "/", scope: "/", display: "standalone", background_color: "#e7e1d4", theme_color: "#1e3328", icons: [ { src: "icon-192.png", sizes: "192x192", type: "image/png" }, { src: "icon-512.png", sizes: "512x512", type: "image/png", purpose: "any maskable", }, ], }, workbox: { // Top-level and assets/ only. A recursive glob would walk every Kachel. globPatterns: ["*.{html,js,svg,woff2}", "assets/**/*.{js,css,woff2}"], globIgnores: ["**/node_modules/**/*", "kacheln/**"], navigateFallback: "index.html", }, }), ], build: { outDir: "public", emptyOutDir: false, copyPublicDir: false, }, test: { environment: "node", include: ["src/**/*.test.ts"], globals: true, }, });