import path from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import tailwindcss from '@tailwindcss/vite'
import { tanstackRouter } from '@tanstack/router-plugin/vite'

// https://vite.dev/config/
export default defineConfig(() => {
  const apiProxyTarget =
    process.env.VITE_API_PROXY_TARGET ?? 'http://127.0.0.1:3000'

  return {
    plugins: [
      tanstackRouter({
        target: 'react',
        autoCodeSplitting: true,
      }),
      react(),
      tailwindcss(),
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
      },
    },
    server: {
      proxy: {
        '/admin': apiProxyTarget,
        '/api': apiProxyTarget,
        '/auth': apiProxyTarget,
        '/health': apiProxyTarget,
        '/info': apiProxyTarget,
      },
    },
  }
})
