import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { componentTagger } from "lovable-tagger";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
  base: process.env.VITE_BASE_PATH || "/",
  server: {
    // Nicht 8080: Cursor belegt localhost:8080 → ERR_EMPTY_RESPONSE im Browser
    host: "localhost",
    port: 5173,
    strictPort: false,
    hmr: {
      overlay: false,
    },
  },
  plugins: [
    react(),
    mode === "development" && componentTagger(),
  ].filter(Boolean),
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
      // ESM-Variante erzwingen, damit BigNumber.isBigNumber im Build verfügbar ist (Appwrite-SDK)
      "bignumber.js": path.resolve(__dirname, "node_modules/bignumber.js/bignumber.mjs"),
    },
  },
  optimizeDeps: {
    include: ["bignumber.js"],
  },
}));
