vite.preload.config.ts 791 B

12345678910111213141516171819202122
  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig } from "vite";
  3. // The sandboxed preload must be a single self-contained CJS file — Electron's
  4. // sandbox require polyfill cannot resolve relative modules ("a bundler is
  5. // required if you need to split preload code into multiple files"). tsc.preload
  6. // type-checks (noEmit); this config bundles src/preload.ts + the shared ipc.ts
  7. // channel constants into one dist/preload/preload.js with electron external.
  8. export default defineConfig({
  9. build: {
  10. outDir: "dist/preload",
  11. emptyOutDir: true,
  12. lib: {
  13. entry: fileURLToPath(new URL("./src/preload.ts", import.meta.url)),
  14. formats: ["cjs"],
  15. fileName: () => "preload.js",
  16. },
  17. rollupOptions: {
  18. external: ["electron"],
  19. },
  20. },
  21. });