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

export default defineConfig({
  plugins: [react()],
  base: './',
  define: {
    // Define process globally to avoid "process is not defined" errors
    'process.env': {},
    'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
    'process.platform': JSON.stringify('win32')
  },
  server: {
    port: 5173,
    strictPort: true,
    fs: {
      // erlaubt Zugriff auf Monorepo-Nachbarordner (z. B. ../shared)
      allow: ['..']
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
    // erhöht Kompatibilität mit verlinkten/local deps
    preserveSymlinks: true,
  },
  optimizeDeps: {
    include: ['@skillmate/shared'],
  },
  build: {
    outDir: 'dist',
    emptyOutDir: true,
    commonjsOptions: {
      include: [/node_modules/, /@skillmate\/shared/],
      transformMixedEsModules: true,
    },
    rollupOptions: {
      external: ['electron'],
    }
  },
})
