import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import { defineConfig, loadEnv } from 'vite';

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, '.', '');

  return {
    base: env.VITE_APP_BASE || '/',
    build: { reportCompressedSize: false, chunkSizeWarningLimit: 2000 },
    plugins: [react(), tailwindcss()],
    define: {
      'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY),
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, '.'),
      },
    },
    server: {
      hmr: process.env.DISABLE_HMR !== 'true',
      proxy: {
        '/api': {
          target: 'http://127.0.0.1:8091',
          changeOrigin: true,
        },
      },
      watch: {
        ignored: [
          '**/.php-sessions/**',
          '**/api/**',
          '**/database/**',
          '**/hosting-ready/**',
          '**/hosting-ready-*/*',
          '**/dist/**',
          '**/vite.log',
        ],
      },
    },
  };
});
