import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { fileURLToPath, URL } from 'node:url' // Plugin pentru a înlocui BUILD_TIMESTAMP în index.html la build function htmlTimestampPlugin() { return { name: 'html-timestamp', transformIndexHtml(html) { return html.replace('BUILD_TIMESTAMP', new Date().toISOString()) } } } export default defineConfig({ plugins: [vue(), htmlTimestampPlugin()], // Base path for production deployment in IIS subdirectory base: process.env.NODE_ENV === 'production' ? '/roa2web/' : '/', resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), '@shared': fileURLToPath(new URL('../../shared', import.meta.url)) } }, server: { port: 3000, host: true, // WSL2 file watching fix - use polling for /mnt/ paths watch: { usePolling: true, // Required for WSL2 when files are on Windows mount interval: 1000 // Check for changes every second }, // HMR configuration for better hot reload hmr: { overlay: true, // Show errors in browser overlay protocol: 'ws', // WebSocket protocol host: 'localhost' // Explicit host for WSL2 }, proxy: { '/api': { target: 'http://localhost:8001', changeOrigin: true, secure: false, configure: (proxy, options) => { proxy.on('proxyReq', (proxyReq, req, res) => { // Preserve authorization header during redirects if (req.headers.authorization) { proxyReq.setHeader('Authorization', req.headers.authorization); } }); } } } }, build: { outDir: 'dist', sourcemap: true, // Cache busting - generează hash-uri noi la fiecare build assetsInlineLimit: 0, // Nu inline asset-uri mici, folosește fișiere separate cu hash rollupOptions: { output: { // Forțează hash-uri unice pentru toate fișierele entryFileNames: `assets/[name].[hash].js`, chunkFileNames: `assets/[name].[hash].js`, assetFileNames: `assets/[name].[hash].[ext]`, manualChunks: { vendor: ['vue', 'vue-router', 'pinia'], primevue: ['primevue/button', 'primevue/datatable', 'primevue/inputtext'], utils: ['axios', 'date-fns'] } } } }, // Adaugă timestamp la build pentru versioning define: { __APP_VERSION__: JSON.stringify(new Date().toISOString()), __BUILD_TIMESTAMP__: JSON.stringify(Date.now()) } })