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

export default defineConfig({
  plugins: [react(), tailwindcss()],
  root: '.',
  publicDir: 'public',
  resolve: {
    alias: { '@': path.resolve(__dirname, './src') },
  },
  build: {
    outDir: 'dist',
    chunkSizeWarningLimit: 700,
    rolldownOptions: {
      output: {
        codeSplitting: {
          groups: [
            {
              name: 'vendor-react',
              test: /node_modules[\\/](react|react-dom|scheduler)[\\/]/,
            },
            {
              name: 'vendor-router',
              test: /node_modules[\\/]@tanstack[\\/]/,
            },
            {
              name: 'vendor-charts',
              test: /node_modules[\\/](recharts|d3-|victory-|lodash)[\\/]/,
            },
            {
              name: 'vendor-monaco',
              test: /node_modules[\\/](@monaco-editor|monaco-editor)[\\/]/,
            },
            {
              name: 'vendor-xterm',
              test: /node_modules[\\/](@xterm|xterm)[\\/]/,
            },
          ],
        },
      },
    },
  },
  server: {
    port: 3000,
    strictPort: true,
    host: true,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8052',
        changeOrigin: true,
        ws: true,
      },
      '/open2api': {
        target: 'http://127.0.0.1:8052',
        changeOrigin: true,
      },
      '/ws': {
        target: 'http://127.0.0.1:8052',
        changeOrigin: true,
        ws: true,
      },
    },
  },
})
