import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { nxViteTsPaths } from "@nx/vite/plugins/nx-tsconfig-paths.plugin";

export default defineConfig({
  root: __dirname,
  // Env lives at the workspace root, shared with the backoffice — without this
  // Vite looks in apps/portal and VITE_BASE_API_URL silently falls back to its
  // built-in default.
  envDir: "../../",
  cacheDir: "../../node_modules/.vite/apps/portal",
  // 3000, not the usual 4200: the Fayda redirect URI registered for local
  // testing is http://localhost:3001/callback, and the provider matches it
  // exactly. The API moves to 3001 to make room.
  server: { port: 3000, host: "localhost" },
  //   server: {
  //   port: 4200,
  //   proxy: {
  //     '/api': {
  //       target: 'http://localhost:3001', // change from 'https://ema-api-dev.triaplc.com'
  //       changeOrigin: true,
  //     },
  //   },
  // },
  preview: { port: 3000, host: "localhost" },
  plugins: [react(), nxViteTsPaths()],
  resolve: {
    dedupe: ["react", "react-dom", "react-router-dom", "@tanstack/react-query"],
  },
  build: {
    outDir: "../../dist/apps/portal",
    emptyOutDir: true,
    reportCompressedSize: true,
  },
});
