import { fileURLToPath, URL } from "node:url"; import fs from "node:fs"; const pkg = JSON.parse(fs.readFileSync(new URL("./package.json", import.meta.url), "utf-8")); import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import vueDevTools from "vite-plugin-vue-devtools"; import { VitePWA } from "vite-plugin-pwa"; import tailwindcss from "@tailwindcss/vite"; const buildTarget = process.env.BUILD_TARGET || "web"; const isFlatpak = buildTarget === "flatpak"; const usesLocalAssets = isFlatpak; const pwaRegisterStub = { name: "pwa-register-stub", resolveId(id) { if (id === "virtual:pwa-register") return "\0virtual:pwa-register-stub"; }, load(id) { if (id === "\0virtual:pwa-register-stub") { return "export function registerSW(){ return () => Promise.resolve(); }"; } }, }; // Vite's dev client needs `unsafe-eval` for hot-module replacement and // `unsafe-inline` for its injected styles, so `npm run dev` would be blocked by // the strict policy in index.html. Swap in a relaxed copy while serving; the // built output keeps the strict one. // // The reloadable tail must track index.html exactly, or dev stops reproducing // production: a dev-only policy that quietly permits more than the shipped one // hides violations until after deploy. frame-src / worker-src / manifest-src // are listed for the same reason as in index.html. const devCspPlugin = { name: "dev-csp", apply: "serve", transformIndexHtml(html) { const relaxed = html.replace( /(