vite.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { readFileSync } from "node:fs"
  2. import solidPlugin from "vite-plugin-solid"
  3. import tailwindcss from "@tailwindcss/vite"
  4. import { fileURLToPath } from "url"
  5. const theme = fileURLToPath(new URL("./public/oc-theme-preload.js", import.meta.url))
  6. const channel = (() => {
  7. const raw = process.env.OPENCODE_CHANNEL
  8. if (raw === "dev" || raw === "beta" || raw === "prod") return raw
  9. if (process.env.OPENCODE_CHANNEL === "latest") return "prod"
  10. return "dev"
  11. })()
  12. /**
  13. * @type {import("vite").PluginOption}
  14. */
  15. export default [
  16. {
  17. name: "opencode-desktop:config",
  18. config() {
  19. return {
  20. resolve: {
  21. alias: {
  22. "@": fileURLToPath(new URL("./src", import.meta.url)),
  23. },
  24. },
  25. define: {
  26. "import.meta.env.VITE_OPENCODE_CHANNEL": JSON.stringify(channel),
  27. },
  28. worker: {
  29. format: "es",
  30. },
  31. }
  32. },
  33. },
  34. {
  35. name: "opencode-desktop:theme-preload",
  36. transformIndexHtml(html) {
  37. return html.replace(
  38. '<script id="oc-theme-preload-script" src="/oc-theme-preload.js"></script>',
  39. `<script id="oc-theme-preload-script">${readFileSync(theme, "utf8")}</script>`,
  40. )
  41. },
  42. },
  43. tailwindcss(),
  44. solidPlugin(),
  45. ]