import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import { fileURLToPath } from 'url'
import { dirname } from 'path'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react({
      jsxRuntime: 'classic', // Classic JSX mode - uses React.createElement
    }),
  ],
  root: 'assets/src',
  base: './',
  build: {
    outDir: resolve(__dirname, 'assets/dist'), // Absolute path to output
    emptyOutDir: true,
    manifest: true,
    assetsDir: '', // Don't nest assets in another folder
    commonjsOptions: {
      include: [/react/, /jsx-runtime/, /node_modules/],
    },
    rollupOptions: {
      input: resolve(__dirname, 'assets/src/main.tsx'),
      output: {
        entryFileNames: 'main.js',
        chunkFileNames: 'chunks/[name]-[hash].js',
        assetFileNames: 'assets/[name]-[hash].[ext]',
      },
    },
  },
  server: {
    host: '138.201.244.222', // Explicit IPv4 address
    port: 5173,
  },
})

