electron.vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { sentryVitePlugin } from "@sentry/vite-plugin"
  2. import { defineConfig } from "electron-vite"
  3. import appPlugin from "@opencode-ai/app/vite"
  4. const channel = (() => {
  5. const raw = process.env.OPENCODE_CHANNEL
  6. if (raw === "dev" || raw === "beta" || raw === "prod") return raw
  7. if (process.env.OPENCODE_CHANNEL === "latest") return "prod"
  8. return "dev"
  9. })()
  10. const nodePtyPkg = `@lydell/node-pty-${process.platform}-${process.arch}`
  11. const sentry =
  12. process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
  13. ? sentryVitePlugin({
  14. authToken: process.env.SENTRY_AUTH_TOKEN,
  15. org: process.env.SENTRY_ORG,
  16. project: process.env.SENTRY_PROJECT,
  17. telemetry: false,
  18. release: {
  19. name: process.env.SENTRY_RELEASE ?? process.env.VITE_SENTRY_RELEASE,
  20. },
  21. sourcemaps: {
  22. assets: "./out/renderer/**",
  23. filesToDeleteAfterUpload: "./out/renderer/**/*.map",
  24. },
  25. })
  26. : false
  27. export default defineConfig({
  28. main: {
  29. define: {
  30. "import.meta.env.OPENCODE_CHANNEL": JSON.stringify(channel),
  31. },
  32. build: {
  33. rollupOptions: {
  34. input: { index: "src/main/index.ts" },
  35. // Keep this identical to electron-vite's Node 20.11+ shim. Its regex insertion can
  36. // corrupt bundled TypeScript, while a Rollup banner places the shim safely.
  37. output: {
  38. banner: `
  39. // -- CommonJS Shims --
  40. import __cjs_mod__ from 'node:module';
  41. const __filename = import.meta.filename;
  42. const __dirname = import.meta.dirname;
  43. const require = __cjs_mod__.createRequire(import.meta.url);
  44. `,
  45. },
  46. },
  47. externalizeDeps: { include: [nodePtyPkg] },
  48. },
  49. plugins: [
  50. {
  51. name: "opencode:node-pty-narrower",
  52. enforce: "pre",
  53. resolveId(s) {
  54. if (s === "@lydell/node-pty") return nodePtyPkg
  55. },
  56. },
  57. ],
  58. },
  59. preload: {
  60. build: {
  61. rollupOptions: {
  62. input: { index: "src/preload/index.ts" },
  63. output: {
  64. format: "cjs",
  65. entryFileNames: "[name].js",
  66. },
  67. },
  68. },
  69. },
  70. renderer: {
  71. plugins: [appPlugin, sentry],
  72. publicDir: "../../../app/public",
  73. root: "src/renderer",
  74. build: {
  75. sourcemap: true,
  76. rollupOptions: {
  77. input: {
  78. main: "src/renderer/index.html",
  79. },
  80. },
  81. },
  82. },
  83. })