/// <reference types="vitest" />

import { cloudflare } from "@cloudflare/vite-plugin";
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { defineConfig, type PluginOption } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig(({ mode }) => {
  const plugins: PluginOption[] = [
    react(),
    tailwindcss(),
    tsconfigPaths({ ignoreConfigErrors: true }),
  ];

  if (mode !== "test" && process.env.VITEST !== "true") {
    plugins.push(cloudflare({ inspectorPort: 9233 }));
  }

  return {
    plugins,
    server: { cors: false },
    test: {
      globals: true,
      environment: "happy-dom",
      setupFiles: "./src/setupTests.ts",
    },
  };
});
