import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { fileURLToPath, URL } from 'node:url';

// Vite: wir halten es erstmal möglichst nah an der bisherigen Vue-CLI-Dev-Experience.
// - Dev-Proxy /api -> Backend
// - Build nach dist/ (wie gewohnt), danach copy-dist -> public/ (bestehender Deploy-Flow)
export default defineConfig(({ mode }) => {
  const backendTarget = process.env.VITE_BACKEND_PROXY || 'http://localhost:3010';

  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    server: {
      host: 'localhost',
      port: Number(process.env.VITE_FRONTEND_PORT || process.env.FRONTEND_PORT || 8080),
      proxy: {
        '/api': {
          target: backendTarget,
          changeOrigin: true,
          secure: false,
        },
      },
    },
    build: {
      outDir: 'dist',
      sourcemap: true,
    },
  };
});

