import { defineConfig } from "vitest/config";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { resolve } from "path";

const apiTarget = process.env.VITE_API_TARGET || "http://localhost:8000";
const inDocker = !!process.env.VITE_API_TARGET;

export default defineConfig({
  plugins: [svelte()],
  build: {
    outDir: "dist",
    emptyOutDir: true,
  },
  server: {
    port: 5173,
    watch: inDocker ? { usePolling: true, interval: 1000 } : undefined,
    proxy: {
      "/api": {
        target: apiTarget,
        changeOrigin: true,
        ws: true,
      },
    },
  },
  test: {
    environment: "jsdom",
    globals: true,
  },
  resolve: {
    conditions: ["browser"],
    alias: {
      $lib: resolve(__dirname, "./src/lib"),
    },
  },
});
