import { defineConfig } from 'astro/config'; import alpinejs from '@astrojs/alpinejs'; // WordPress plugin specific configuration export default defineConfig({ // Source and output directories root: './src/astro', publicDir: './src/astro/public', outDir: './admin/assets/dist', // Integrations integrations: [ alpinejs() ], // Build configuration for WordPress compatibility build: { // Generate assets that work with WordPress format: 'file', // Generate .html files instead of directories assets: 'assets', // Asset directory name rollupOptions: { input: { // Admin page entries that we actually created 'admin-dashboard': './src/astro/pages/admin-dashboard.astro', 'backup': './src/astro/pages/backup.astro', 'restore': './src/astro/pages/restore.astro', 'settings': './src/astro/pages/settings.astro' }, output: { // WordPress-friendly asset naming entryFileNames: 'js/[name]-[hash].js', chunkFileNames: 'js/chunks/[name]-[hash].js', assetFileNames: (assetInfo) => { const extType = assetInfo.name.split('.').at(1); if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) { return `images/[name]-[hash][extname]`; } if (/css/i.test(extType)) { return `css/[name]-[hash][extname]`; } return `assets/[name]-[hash][extname]`; } }, // Don't bundle WordPress globals external: [ 'jQuery', 'wp', 'ajaxurl', 'wpApiSettings' ] }, // Enable source maps for development sourcemap: process.env.NODE_ENV === 'development' }, // Vite configuration vite: { // WordPress integration defines define: { '__WP_NONCE__': JSON.stringify('${wp_nonce}'), '__WP_AJAX_URL__': JSON.stringify('${ajax_url}'), '__WP_REST_URL__': JSON.stringify('${rest_url}'), '__PLUGIN_URL__': JSON.stringify('${plugin_url}') }, build: { // CSS handling for WordPress cssCodeSplit: true, // Browser compatibility target: ['es2018'], rollupOptions: { output: { // Separate vendor chunks for better caching manualChunks: { 'alpine': ['alpinejs'], 'vendor': ['@astrojs/alpinejs'] }, // Global variable mapping for externals globals: { 'jQuery': 'jQuery', 'wp': 'wp', 'ajaxurl': 'ajaxurl', 'wpApiSettings': 'wpApiSettings' } } } }, // CSS preprocessing - simplified for now css: { // WordPress-compatible CSS processing devSourcemap: true }, // Development server configuration server: { port: 4321, host: true, open: false // Don't auto-open browser } }, });