Files
SaaS-PDF/frontend/vite.config.ts
Your Name 3e1c0e5f99 perf: Optimize PageSpeed performance score
- Replace 2.2MB social-preview.svg with lightweight 1KB vector SVG
- Remove lucide-react manual chunk (rely on tree-shaking instead)
- Separate react-router-dom into its own 'router' chunk
- Add build.target es2020 and chunkSizeWarningLimit
- Add modulepreload hint for main entry point
- Google Fonts already uses media=print non-blocking pattern
- i18n already lazy-loads ar/fr dynamically
- AdSlot already loads AdSense dynamically with intersection observer

Expected improvement: 34 → 70+ on mobile PageSpeed
2026-04-01 07:58:40 +02:00

97 lines
2.0 KiB
TypeScript

/// <reference types="vitest/config" />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
function getAllowedHosts() {
const defaultHosts = ['dociva.io', 'www.dociva.io', 'localhost', '127.0.0.1'];
const siteDomain = process.env.VITE_SITE_DOMAIN;
if (!siteDomain) {
return defaultHosts;
}
try {
const hostname = new URL(siteDomain).hostname;
return Array.from(new Set([...defaultHosts, hostname]));
} catch {
return defaultHosts;
}
}
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts'],
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
port: 5173,
host: true,
allowedHosts: getAllowedHosts(),
proxy: {
'/api': {
target: 'http://backend:5000',
changeOrigin: true,
},
},
},
preview: {
host: true,
allowedHosts: getAllowedHosts(),
},
build: {
outDir: 'dist',
sourcemap: false,
cssMinify: true,
target: 'es2020',
chunkSizeWarningLimit: 600,
minify: 'esbuild',
rollupOptions: {
output: {
manualChunks(id) {
if (!id.includes('node_modules')) {
return undefined;
}
if (id.includes('react-dom') || id.includes('/react/')) {
return 'vendor';
}
if (id.includes('react-router-dom')) {
return 'router';
}
if (id.includes('i18next') || id.includes('react-i18next')) {
return 'i18n';
}
if (id.includes('react-helmet-async')) {
return 'helmet';
}
if (id.includes('/axios/')) {
return 'network';
}
if (id.includes('/pdf-lib/')) {
return 'pdf-core';
}
if (id.includes('/fabric/')) {
return 'editor';
}
return undefined;
},
},
},
},
});