import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' // https://vite.dev/config/ export default defineConfig(async ({ command }) => { // `vite-plugin-vue-devtools` (via @vue/devtools-kit) can access `localStorage` // at import time, which crashes when Vite loads this config in Node. // Load it lazily and only for the dev server. const plugins = [vue()] // Opt-in only: enable by running `VITE_VUE_DEVTOOLS=true npm run dev` // This avoids Node-side crashes when loading the Vite config. if (command === 'serve' && process.env.VITE_VUE_DEVTOOLS === 'true') { const { default: vueDevTools } = await import('vite-plugin-vue-devtools') plugins.push(vueDevTools()) } return { plugins, resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) }, }, build: { // Optimize for SEO and performance cssCodeSplit: true, minify: 'terser', terserOptions: { compress: { drop_console: true, drop_debugger: true } }, rollupOptions: { output: { // Optimize chunk splitting for better caching manualChunks: { 'vue-vendor': ['vue', 'vue-router'], 'ui-components': [ './src/components/ProjectCard.vue', './src/components/TechBadge.vue', './src/components/ContactMethod.vue' ] }, // Use content hash for better caching chunkFileNames: 'assets/js/[name]-[hash].js', entryFileNames: 'assets/js/[name]-[hash].js', assetFileNames: 'assets/[ext]/[name]-[hash].[ext]' } }, // Enable source maps for better debugging sourcemap: false, // Increase chunk size warning limit chunkSizeWarningLimit: 1000 }, // Optimize dependencies optimizeDeps: { include: ['vue', 'vue-router'] } } })