vite.config.ts

2.1 KB · raw

1import { defineConfig } from "vite";2import solidPlugin from "vite-plugin-solid";3import { crx } from "@crxjs/vite-plugin";4import { copyFileSync, mkdirSync, readFileSync } from "fs";5import { resolve } from "path";67const target = process.env.BUILD_TARGET || "chrome";8const manifestPath = target === "firefox" ? "./manifest.firefox.json" : "./manifest.json";9const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));10const passkeyE2E = process.env.PEACH_E2E_PASSKEYS === "1";11const outDir = target === "firefox" ? "dist-firefox" : "dist-chrome";1213// Copy the pdf.js worker into the build output so the popup can load it via14// chrome.runtime.getURL('pdf.worker.min.mjs'). The pdfjs-dist module's default15// workerSrc points inside node_modules, which is not reachable from a packaged16// extension — the worker file must sit alongside the rest of the assets.17const copyPdfJsWorker = {18  name: "copy-pdfjs-worker",19  closeBundle() {20    mkdirSync(outDir, { recursive: true });21    copyFileSync(22      resolve("node_modules/pdfjs-dist/build/pdf.worker.min.mjs"),23      resolve(outDir, "pdf.worker.min.mjs"),24    );25  },26};2728export default defineConfig({29  plugins: [30    solidPlugin(),31    crx({ manifest, browser: target === "firefox" ? "firefox" : "chrome" }),32    copyPdfJsWorker,33  ],34  base: "./",35  define: {36    __PEACH_E2E_PASSKEYS__: JSON.stringify(passkeyE2E),37  },38  build: {39    outDir,40    // emptyOutDir must stay false. When true, Vite tries to remove the41    // contents of the outDir before each build, which throws EPERM on FUSE42    // and some mounted filesystems and aborts the whole build. Overwriting43    // in place works everywhere.44    emptyOutDir: false,45    target: "esnext",46    rollupOptions: {47      output: {48        manualChunks(id) {49          if (id.includes("node_modules/solid-js")) return "vendor-solid";50          if (id.includes("node_modules/otpauth")) return "vendor-otp";51          if (id.includes("node_modules/papaparse")) return "vendor-parse";52          if (id.includes("node_modules/qrcode")) return "vendor-qr";53        },54      },55    },56  },57});