Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import { readFileSync } from "node:fs"import { createRequire } from "node:module"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) }}
// The markdown worker imports these directly, so they are served unbundled to keep worker startup// stable. Vite applies `exclude` to every import inside a pre-bundle too, which would leave a bare// `import "marked"` in mermaid's chunk that the browser cannot resolve from this package.const workerDeps = ["@shikijs/stream", "marked", "marked-shiki", "remend"]
/** @type {import("rolldown").Plugin} */const bundleNestedWorkerDeps = { name: "opencode-desktop:bundle-nested-worker-deps", resolveId(id, importer) { if (!importer || !workerDeps.includes(id) || !importer.includes("node_modules")) return try { return createRequire(importer).resolve(id) } catch { return } },}
export 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: workerDeps, include: ["@opencode/session-ui > mermaid", "@opencode/session-ui > mermaid > katex"], rolldownOptions: { plugins: [bundleNestedWorkerDeps] }, }, } }, }, { name: "opencode-desktop:theme-preload", transformIndexHtml: { order: "pre", handler: inlineThemePreload, }, }, ...tailwind, solidPlugin(),]
export function inlineThemePreload(html) { return html.replace( /<script id="oc-theme-preload-script" src="(?:\.\/|\/)oc-theme-preload\.js"><\/script>/, `<script id="oc-theme-preload-script">${themeScript}</script>`, )}