import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  plugins: [vue()],
  mode: 'development',
  build: {
    chunkSizeWarningLimit: 700,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (!id.includes('node_modules')) {
            return;
          }

          if (id.includes('vue-router')) return 'router';
          if (id.includes('vue-i18n')) return 'i18n';
          if (id.includes('vuex')) return 'store';
          if (id.includes('socket.io-client')) return 'socket';
          if (id.includes('html2canvas')) return 'html2canvas';
          if (id.includes('jspdf')) return 'jspdf';
          if (id.includes('sortablejs')) return 'sortable';
          if (id.includes('crypto-js')) return 'crypto';
          if (id.includes('axios')) return 'http';

          return 'vendor';
        }
      }
    }
  },
  resolve: {
    alias: {
      '@': '/src'
    }
  },
  server: {
    host: true,
    allowedHosts: ['trainer.localhost', 'club.localhost', 'player.localhost'],
    port: 5000,
    watch: {
      usePolling: true,
    },
    hmr: {
      protocol: 'ws',
      port: 5000,
    }
  },
});
