import path from 'path'
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks: (id: string) => {
          if (id.includes('node_modules/bpmn-js') || id.includes('node_modules/diagram-js')) return 'vendor-bpmn'
          if (id.includes('node_modules/echarts') || id.includes('node_modules/zrender')) return 'vendor-charts'
          if (id.includes('node_modules/react') || id.includes('node_modules/react-dom')) return 'vendor-react'
          if (id.includes('node_modules/@tanstack')) return 'vendor-router'
          if (id.includes('node_modules/@radix-ui')) return 'vendor-ui'
        },
      },
    },
  },
  optimizeDeps: {
    include: ['bpmn-js'],
  },
  test: {
    environment: 'jsdom',
    globals: true,
    setupFiles: ['./tests/setup.ts'],
    exclude: ['**/node_modules/**', '**/dist/**', 'tests/e2e/**'],
  },
})
