import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default defineConfig({
  plugins: [vue()],
  root: __dirname,
  server: {
    port: 5175,
    hmr: false,
    proxy: {
      '/api': {
        target: 'http://localhost:3300',
        changeOrigin: true,
        secure: false,
        ws: false
      },
      '/static': {
        target: 'http://localhost:3300',
        changeOrigin: true,
        secure: false
      }
    },
    watch: {
      ignored: [
        '**/node_modules/**',
        '**/dist/**',
        '**/.git/**',
        resolve(__dirname, '../server/**'),
        resolve(__dirname, '../docroot/**'),
        resolve(__dirname, '../src/**'),
        resolve(__dirname, '../logs/**'),
        '!**/client/src/**'
      ]
    }
  },
  build: {
    outDir: 'dist',
    emptyOutDir: true,
    assetsDir: 'assets',
    sourcemap: false,
    minify: 'terser',
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            if (id.includes('vue') || id.includes('vue-router') || id.includes('pinia')) {
              return 'vue-vendor';
            }
            if (id.includes('socket.io-client')) {
              return 'socket-vendor';
            }
          }
          // Standard-Chunks Vite überlassen
          return undefined;
        }
      }
    }
  }
});

