import { readFileSync } from "node:fs" import solidPlugin from "vite-plugin-solid" import tailwindcss from "@tailwindcss/vite" import { fileURLToPath } from "url" const theme = fileURLToPath(new URL("./public/oc-theme-preload.js", import.meta.url)) const themeScript = readFileSync(theme, "utf8") const tailwind = tailwindcss() const tailwindGenerate = tailwind.find((plugin) => plugin.name === "@tailwindcss/vite:generate:serve") const tailwindHotUpdate = tailwindGenerate?.hotUpdate // Tailwind 4.3.3 expects a server that Vite's bundled dev hook does not provide. if (tailwindGenerate && typeof tailwindHotUpdate === "function") { tailwindGenerate.hotUpdate = function (context) { if (!context.server) return return tailwindHotUpdate.call(this, context) } } const channel = (() => { const raw = process.env.OPENCODE_CHANNEL if (raw === "local" || raw === "dev" || raw === "beta" || raw === "prod") return raw if (process.env.OPENCODE_CHANNEL === "latest") return "prod" return "dev" })() /** * @type {import("vite").PluginOption} */ export default [ { name: "opencode-desktop:config", config() { return { resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, define: { "import.meta.env.VITE_OPENCODE_CHANNEL": JSON.stringify(channel), }, worker: { format: "es", }, optimizeDeps: { exclude: ["@shikijs/stream", "marked", "marked-shiki", "remend"], include: ["@opencode-ai/session-ui > mermaid", "@opencode-ai/session-ui > mermaid > katex"], }, } }, }, { name: "opencode-desktop:theme-preload", transformIndexHtml: { order: "pre", handler: inlineThemePreload, }, }, ...tailwind, solidPlugin(), ] export function inlineThemePreload(html) { return html.replace( /`, ) }