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

const buildOutDir =
  process.env.ADMINFRONT_BUILD_OUT_DIR ?? "/tmp/baron-sso-adminfront-dist";

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "lucide-react": path.resolve(process.cwd(), "node_modules/lucide-react"),
      react: path.resolve(process.cwd(), "node_modules/react"),
      "react-dom": path.resolve(process.cwd(), "node_modules/react-dom"),
    },
    dedupe: ["react", "react-dom", "react-router-dom"],
  },
  cacheDir:
    process.env.ADMINFRONT_VITE_CACHE_DIR ??
    "/tmp/baron-sso-adminfront-vite-cache",
  envPrefix: ["VITE_", "USERFRONT_", "ORGFRONT_"],
  build: {
    outDir: buildOutDir,
  },
  server: {
    host: "127.0.0.1",
    proxy: {
      "/api": {
        target: process.env.API_PROXY_TARGET || "http://localhost:3000",
        changeOrigin: true,
      },
    },
  },
  preview: {
    host: "127.0.0.1",
    proxy: {
      "/api": {
        target: process.env.API_PROXY_TARGET || "http://localhost:3000",
        changeOrigin: true,
      },
    },
  },
});
