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

export default defineConfig({
  plugins: [react()],
  server: {
    port: 34825,
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  build: {
    outDir: 'dist',
    emptyOutDir: true,
    rollupOptions: {
      input: './src/index.tsx',
      output: {
        format: 'iife',
        entryFileNames: 'admin.js',
        assetFileNames: '[name].[ext]',
        globals: {
          '@wordpress/i18n': 'wp.i18n',
        },
      },
      // Externalize @wordpress/i18n - WordPress provides it globally as wp.i18n
      external: ['@wordpress/i18n'],
    },
  },
})
