import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import path from 'path'; // Builds the admin app as one IIFE script plus one stylesheet, which the PHP // side enqueues with wp_enqueue_script()/wp_enqueue_style(). export default defineConfig({ plugins: [react()], root: path.resolve(__dirname), base: './', build: { outDir: path.resolve(__dirname, 'build'), emptyOutDir: true, sourcemap: false, cssCodeSplit: false, target: 'es2019', rollupOptions: { input: path.resolve(__dirname, 'src/main.tsx'), output: { format: 'iife', entryFileNames: 'js/admin.js', chunkFileNames: 'js/[name].js', assetFileNames: (assetInfo) => { const name = assetInfo.names?.[0] ?? assetInfo.name ?? ''; if (name.endsWith('.css')) return 'css/admin.css'; return 'assets/[name][extname]'; }, }, }, }, define: { 'process.env.NODE_ENV': JSON.stringify('production'), }, resolve: { alias: { '@': path.resolve(__dirname, 'src'), // Workspace packages resolve to source so they are bundled in. '@cra-compliance/shared': path.resolve(__dirname, '../../../packages/shared/src/browser.ts'), '@cra-compliance/types': path.resolve(__dirname, '../../../packages/types/src/index.ts'), }, }, });