vite.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import solidPlugin from "vite-plugin-solid"
  2. import tailwindcss from "@tailwindcss/vite"
  3. import { fileURLToPath } from "url"
  4. import { generatePreloadScript } from "@opencode-ai/ui/theme"
  5. /**
  6. * Vite plugin that injects the theme preload script into index.html.
  7. * This ensures the theme is applied before the page renders, avoiding FOUC.
  8. * @type {import("vite").Plugin}
  9. */
  10. const themePreloadPlugin = {
  11. name: "opencode-desktop:theme-preload",
  12. transformIndexHtml(html) {
  13. const script = generatePreloadScript()
  14. return html.replace(
  15. /<script id="oc-theme-preload-script">\s*\/\* THEME_PRELOAD_SCRIPT \*\/\s*<\/script>/,
  16. `<script id="oc-theme-preload-script">${script}</script>`,
  17. )
  18. },
  19. }
  20. /**
  21. * @type {import("vite").PluginOption}
  22. */
  23. export default [
  24. {
  25. name: "opencode-desktop:config",
  26. config() {
  27. return {
  28. resolve: {
  29. alias: {
  30. "@": fileURLToPath(new URL("./src", import.meta.url)),
  31. },
  32. },
  33. worker: {
  34. format: "es",
  35. },
  36. }
  37. },
  38. },
  39. themePreloadPlugin,
  40. tailwindcss(),
  41. solidPlugin(),
  42. ]