| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import { sentryVitePlugin } from "@sentry/vite-plugin"
- import { defineConfig } from "electron-vite"
- import appPlugin from "@opencode-ai/app/vite"
- const channel = (() => {
- const raw = process.env.OPENCODE_CHANNEL
- if (raw === "dev" || raw === "beta" || raw === "prod") return raw
- if (process.env.OPENCODE_CHANNEL === "latest") return "prod"
- return "dev"
- })()
- const nodePtyPkg = `@lydell/node-pty-${process.platform}-${process.arch}`
- const sentry =
- process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
- ? sentryVitePlugin({
- authToken: process.env.SENTRY_AUTH_TOKEN,
- org: process.env.SENTRY_ORG,
- project: process.env.SENTRY_PROJECT,
- telemetry: false,
- release: {
- name: process.env.SENTRY_RELEASE ?? process.env.VITE_SENTRY_RELEASE,
- },
- sourcemaps: {
- assets: "./out/renderer/**",
- filesToDeleteAfterUpload: "./out/renderer/**/*.map",
- },
- })
- : false
- export default defineConfig({
- main: {
- define: {
- "import.meta.env.OPENCODE_CHANNEL": JSON.stringify(channel),
- },
- build: {
- rollupOptions: {
- input: { index: "src/main/index.ts" },
- // Keep this identical to electron-vite's Node 20.11+ shim. Its regex insertion can
- // corrupt bundled TypeScript, while a Rollup banner places the shim safely.
- output: {
- banner: `
- // -- CommonJS Shims --
- import __cjs_mod__ from 'node:module';
- const __filename = import.meta.filename;
- const __dirname = import.meta.dirname;
- const require = __cjs_mod__.createRequire(import.meta.url);
- `,
- },
- },
- externalizeDeps: { include: [nodePtyPkg] },
- },
- plugins: [
- {
- name: "opencode:node-pty-narrower",
- enforce: "pre",
- resolveId(s) {
- if (s === "@lydell/node-pty") return nodePtyPkg
- },
- },
- ],
- },
- preload: {
- build: {
- rollupOptions: {
- input: { index: "src/preload/index.ts" },
- output: {
- format: "cjs",
- entryFileNames: "[name].js",
- },
- },
- },
- },
- renderer: {
- plugins: [appPlugin, sentry],
- publicDir: "../../../app/public",
- root: "src/renderer",
- build: {
- sourcemap: true,
- rollupOptions: {
- input: {
- main: "src/renderer/index.html",
- },
- },
- },
- },
- })
|