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

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  // Load env file based on mode
  const env = loadEnv(mode, process.cwd(), '')
  
  return {
  plugins: [react()],
  base: './',

  server: {
      host: env.VITE_DEV_HOST || '192.168.200.10',
      allowedHosts: [env.VITE_DEV_ALLOWED_HOST || 'test.exbytestudios.com'],
      port: parseInt(env.VITE_DEV_PORT || '5173'),
    strictPort: true,
    // HMR via public domain (for dev mode through nginx proxy)
    hmr: {
        protocol: 'wss',
        host: env.VITE_DEV_ALLOWED_HOST || 'test.exbytestudios.com',
        clientPort: 443,
    },
  },

  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  build: {
    outDir: 'dist/renderer',
    emptyOutDir: true,
    rollupOptions: {
      input: {
        main: path.resolve(__dirname, 'index.html'),
      },
    },
  },
  }
}) 