import { defineConfig } from "vite"; import solidPlugin from "vite-plugin-solid"; import { crx } from "@crxjs/vite-plugin"; import { readFileSync } from "fs"; const target = process.env.BUILD_TARGET || "chrome"; const manifestPath = target === "firefox" ? "./manifest.firefox.json" : "./manifest.json"; const manifest = JSON.parse(readFileSync(manifestPath, "utf-8")); const passkeyE2E = process.env.PEACH_E2E_PASSKEYS === "1"; export default defineConfig({ plugins: [solidPlugin(), crx({ manifest, browser: target === "firefox" ? "firefox" : "chrome" })], base: "./", define: { __PEACH_E2E_PASSKEYS__: JSON.stringify(passkeyE2E), }, build: { outDir: target === "firefox" ? "dist-firefox" : "dist-chrome", // emptyOutDir must stay false. When true, Vite tries to remove the // contents of the outDir before each build, which throws EPERM on FUSE // and some mounted filesystems and aborts the whole build. Overwriting // in place works everywhere. emptyOutDir: false, target: "esnext", rollupOptions: { output: { manualChunks(id) { if (id.includes("node_modules/solid-js")) return "vendor-solid"; if (id.includes("node_modules/otpauth")) return "vendor-otp"; if (id.includes("node_modules/papaparse")) return "vendor-parse"; if (id.includes("node_modules/qrcode")) return "vendor-qr"; }, }, }, }, });