vite.config.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { sites } from '@openai/sites-vite-plugin';
  2. import tailwindcss from '@tailwindcss/postcss';
  3. import vinext from 'vinext';
  4. import { defineConfig } from 'vite';
  5. import hostingConfig from './.openai/hosting.json';
  6. const SITE_CREATOR_PLACEHOLDER_DATABASE_ID =
  7. '00000000-0000-4000-8000-000000000000';
  8. const { d1, r2 } = hostingConfig;
  9. // macOS Seatbelt blocks FSEvents, so Codex previews need polling for HMR.
  10. const isCodexSeatbeltSandbox = process.env.CODEX_SANDBOX === 'seatbelt';
  11. const localBindingConfig = {
  12. main: 'vinext/server/fetch-handler',
  13. compatibility_flags: ['nodejs_compat'],
  14. d1_databases: d1
  15. ? [
  16. {
  17. binding: d1,
  18. database_name: 'site-creator-d1',
  19. database_id: SITE_CREATOR_PLACEHOLDER_DATABASE_ID,
  20. },
  21. ]
  22. : [],
  23. r2_buckets: r2
  24. ? [
  25. {
  26. binding: r2,
  27. bucket_name: 'site-creator-r2',
  28. },
  29. ]
  30. : [],
  31. };
  32. export default defineConfig(async () => {
  33. // Keep Wrangler and Miniflare state project-local. These are non-secret tool
  34. // settings; application environment belongs in ignored `.env*` files.
  35. process.env.WRANGLER_WRITE_LOGS ??= 'false';
  36. process.env.WRANGLER_LOG_PATH ??= '.wrangler/logs';
  37. process.env.MINIFLARE_REGISTRY_PATH ??= '.wrangler/registry';
  38. // Wrangler snapshots its log path while the Cloudflare plugin is imported.
  39. const { cloudflare } = await import('@cloudflare/vite-plugin');
  40. return {
  41. css: { postcss: { plugins: [tailwindcss()] } },
  42. server: isCodexSeatbeltSandbox
  43. ? { watch: { useFsEvents: false, usePolling: true } }
  44. : undefined,
  45. plugins: [
  46. vinext(),
  47. sites(),
  48. cloudflare({
  49. viteEnvironment: { name: 'rsc', childEnvironments: ['ssr'] },
  50. config: localBindingConfig,
  51. }),
  52. ],
  53. };
  54. });