74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { defineConfig } from "electron-vite"
|
|
import appPlugin from "@opencode-ai/app/vite"
|
|
import * as fs from "node:fs/promises"
|
|
|
|
const channel = (() => {
|
|
const raw = process.env.OPENCODE_CHANNEL
|
|
if (raw === "dev" || raw === "beta" || raw === "prod") return raw
|
|
return "dev"
|
|
})()
|
|
|
|
const OPENCODE_SERVER_DIST = "../opencode/dist/node"
|
|
|
|
const nodePtyPkg = `@lydell/node-pty-${process.platform}-${process.arch}`
|
|
|
|
export default defineConfig({
|
|
main: {
|
|
define: {
|
|
"import.meta.env.OPENCODE_CHANNEL": JSON.stringify(channel),
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
input: { index: "src/main/index.ts" },
|
|
},
|
|
externalizeDeps: { include: [nodePtyPkg] },
|
|
},
|
|
plugins: [
|
|
{
|
|
name: "opencode:node-pty-narrower",
|
|
enforce: "pre",
|
|
resolveId(s) {
|
|
if (s === "@lydell/node-pty") return nodePtyPkg
|
|
},
|
|
},
|
|
{
|
|
name: "opencode:virtual-server-module",
|
|
enforce: "pre",
|
|
resolveId(id) {
|
|
if (id === "virtual:opencode-server") return this.resolve(`${OPENCODE_SERVER_DIST}/node.js`)
|
|
},
|
|
},
|
|
{
|
|
name: "opencode:copy-server-assets",
|
|
enforce: "post",
|
|
async closeBundle() {
|
|
for (const l of await fs.readdir(OPENCODE_SERVER_DIST)) {
|
|
if (!l.endsWith(".wasm")) continue
|
|
await fs.writeFile(`./out/main/chunks/${l}`, await fs.readFile(`${OPENCODE_SERVER_DIST}/${l}`))
|
|
}
|
|
},
|
|
},
|
|
],
|
|
},
|
|
preload: {
|
|
build: {
|
|
rollupOptions: {
|
|
input: { index: "src/preload/index.ts" },
|
|
},
|
|
},
|
|
},
|
|
renderer: {
|
|
plugins: [appPlugin],
|
|
publicDir: "../../../app/public",
|
|
root: "src/renderer",
|
|
build: {
|
|
rollupOptions: {
|
|
input: {
|
|
main: "src/renderer/index.html",
|
|
loading: "src/renderer/loading.html",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|