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

export default defineConfig({
  plugins: [react()],
  server: {
    port: 3098,
    host: true
  },
  build: {
    outDir: 'dist',
    sourcemap: false,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (!id.includes('node_modules')) return
          if (id.includes('jspdf')) return 'vendor-pdf'
          if (id.includes('lucide-react')) return 'vendor-icons'
          if (
            id.includes('react-markdown') ||
            id.includes('/marked/') ||
            id.includes('remark-') ||
            id.includes('mdast') ||
            id.includes('micromark') ||
            id.includes('unist')
          ) {
            return 'vendor-markdown'
          }
          if (id.includes('react-router')) return 'vendor-router'
          if (
            /[/\\]node_modules[/\\]react-dom[/\\]/.test(id) ||
            /[/\\]node_modules[/\\]react[/\\]/.test(id) ||
            /[/\\]node_modules[/\\]scheduler[/\\]/.test(id)
          ) {
            return 'vendor-react'
          }
        },
      },
    },
  },
})
