import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { resolve } from 'path' import { VitePWA } from 'vite-plugin-pwa' // Optimized Vite Configuration with PWA Support export default defineConfig({ plugins: [ react(), VitePWA({ registerType: 'prompt', includeAssets: ['favicon.svg', 'robots.txt', 'site.webmanifest'], manifest: { name: 'Miracles in Motion', short_name: 'MiM', description: 'A 501(c)(3) nonprofit providing students with essential support', theme_color: '#7c3aed', background_color: '#ffffff', display: 'standalone', scope: '/', start_url: '/', icons: [ { src: '/favicon.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any maskable' } ] }, workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,webp}'], runtimeCaching: [ { urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i, handler: 'CacheFirst', options: { cacheName: 'google-fonts-cache', expiration: { maxEntries: 10, maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year } } }, { urlPattern: /\.(png|jpg|jpeg|svg|gif|webp)$/, handler: 'CacheFirst', options: { cacheName: 'images-cache', expiration: { maxEntries: 50, maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days } } } ] }, devOptions: { enabled: true } }) ], resolve: { alias: { '@': resolve(__dirname, './src'), }, }, server: { port: 3000, open: true, }, build: { outDir: 'dist', sourcemap: true, rollupOptions: { output: { manualChunks: { // Core React libraries vendor: ['react', 'react-dom'], // UI and animations ui: ['framer-motion', 'lucide-react'], // AI libraries (browser-compatible) ai: ['@tensorflow/tfjs'], // Utilities and i18n utils: ['date-fns', 'react-helmet-async', 'i18next', 'react-i18next'], // Stripe and payment payments: ['@stripe/stripe-js', '@stripe/react-stripe-js'] }, chunkFileNames: 'js/[name]-[hash].js' } }, // Enable compression minify: 'terser', terserOptions: { compress: { drop_console: true, drop_debugger: true, }, }, // Optimize chunks chunkSizeWarningLimit: 500, }, })