import { defineConfig } from 'vite'
import { configDefaults } from 'vitest/config'
import react from '@vitejs/plugin-react-swc'

export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('supertokens-auth-react/recipe/thirdparty')) {
            return 'auth-thirdparty-vendor'
          }
          if (id.includes('supertokens-auth-react/recipe/emailpassword')) {
            return 'auth-email-vendor'
          }
          if (id.includes('supertokens-auth-react/recipe/session')) {
            return 'auth-session-vendor'
          }
          if (id.includes('supertokens-auth-react')) {
            return 'auth-core-vendor'
          }
          if (id.includes('react-router-dom') || id.includes('@tanstack/react-query')) {
            return 'app-vendor'
          }
          if (id.includes('lucide-react')) {
            return 'icon-vendor'
          }
          return undefined
        },
      },
    },
  },
  server: {
    port: 4273,
  },
  preview: {
    port: 4274,
  },
  test: {
    environment: 'jsdom',
    include: [
      'src/**/*.{test,spec}.{ts,tsx}',
      'src/**/__tests__/**/*.{ts,tsx}',
      'server/src/**/*.{test,spec}.ts',
      'server/src/**/__tests__/**/*.ts',
      'scripts/**/*.{test,spec}.mjs',
    ],
    exclude: [...configDefaults.exclude, 'tests/e2e/**'],
  },
})
