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

// https://vite.dev/config/
export default defineConfig({
  plugins: [react(), tailwindcss()],
  build: {
    outDir: '../assets',
    // The plugin ships non-admin frontend assets in the same folder.
    // Keep Vite from deleting checkout.css / checkout.js on admin rebuilds.
    emptyOutDir: false,
    rollupOptions: {
      output: {
        entryFileNames: 'js/app.js',
        chunkFileNames: 'js/[name]-[hash].js',
        assetFileNames: (assetInfo) => {
          const name = assetInfo.name || '';
          if (name.endsWith('.css')) {
            return 'css/app.css';
          }
          return 'media/[name]-[hash][extname]';
        }
      }
    }
  }
})
