123 lines
4.2 KiB
TypeScript
123 lines
4.2 KiB
TypeScript
import { defineConfig } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import svgr from "vite-plugin-svgr";
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
const isDev = mode === "development";
|
|
|
|
return {
|
|
plugins: [
|
|
react(),
|
|
svgr({
|
|
svgrOptions: {
|
|
icon: true,
|
|
// This will transform your SVG to a React component
|
|
exportType: "named",
|
|
namedExport: "ReactComponent",
|
|
},
|
|
}),
|
|
],
|
|
// Optimize dependency pre-bundling
|
|
optimizeDeps: {
|
|
include: [
|
|
'react-apexcharts',
|
|
'apexcharts',
|
|
'clsx',
|
|
'tailwind-merge',
|
|
],
|
|
exclude: [], // Don't exclude anything
|
|
esbuildOptions: {
|
|
// Increase timeout for large dependencies
|
|
target: 'es2020',
|
|
},
|
|
},
|
|
// Build configuration for code splitting
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
// Manual chunk splitting for better code splitting
|
|
manualChunks: (id) => {
|
|
// Vendor chunks - separate large dependencies
|
|
if (id.includes('node_modules')) {
|
|
// React and React DOM together
|
|
if (id.includes('react') || id.includes('react-dom') || id.includes('react-router')) {
|
|
return 'vendor-react';
|
|
}
|
|
// Chart libraries
|
|
if (id.includes('apexcharts') || id.includes('recharts')) {
|
|
return 'vendor-charts';
|
|
}
|
|
// UI libraries
|
|
if (id.includes('@radix-ui') || id.includes('framer-motion')) {
|
|
return 'vendor-ui';
|
|
}
|
|
// Other large vendors
|
|
return 'vendor';
|
|
}
|
|
// Page chunks - each page gets its own chunk
|
|
if (id.includes('/pages/')) {
|
|
const match = id.match(/\/pages\/([^/]+)/);
|
|
if (match) {
|
|
const pageName = match[1];
|
|
// Group by module
|
|
if (pageName === 'Planner' || id.includes('/Planner/')) {
|
|
return 'pages-planner';
|
|
}
|
|
if (pageName === 'Writer' || id.includes('/Writer/')) {
|
|
return 'pages-writer';
|
|
}
|
|
if (pageName === 'Thinker' || id.includes('/Thinker/')) {
|
|
return 'pages-thinker';
|
|
}
|
|
if (pageName === 'Settings' || id.includes('/Settings/')) {
|
|
return 'pages-settings';
|
|
}
|
|
if (pageName === 'Billing' || id.includes('/Billing/')) {
|
|
return 'pages-billing';
|
|
}
|
|
// Individual page chunks for others
|
|
return `page-${pageName.toLowerCase()}`;
|
|
}
|
|
}
|
|
},
|
|
// Optimize chunk file names
|
|
chunkFileNames: 'assets/js/[name]-[hash].js',
|
|
entryFileNames: 'assets/js/[name]-[hash].js',
|
|
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
|
|
},
|
|
},
|
|
// Increase chunk size warning limit (default is 500kb)
|
|
chunkSizeWarningLimit: 1000,
|
|
// Enable source maps in dev only
|
|
sourcemap: isDev,
|
|
},
|
|
// Only configure server and HMR in development mode
|
|
...(isDev && {
|
|
server: {
|
|
host: "0.0.0.0", // Allow external connections (for Docker)
|
|
port: 5173,
|
|
strictPort: false, // Allow port fallback if 5173 is busy
|
|
allowedHosts: [
|
|
"app.igny8.com",
|
|
"localhost",
|
|
"127.0.0.1",
|
|
],
|
|
watch: {
|
|
usePolling: true, // Needed for file watching in Docker
|
|
},
|
|
hmr: {
|
|
// Behind reverse proxy - use same origin strategy
|
|
// Client connects via public domain (app.igny8.com) on default HTTPS port (443)
|
|
// Caddy automatically proxies WebSocket upgrades from 443 to 5173
|
|
protocol: "wss",
|
|
// Don't specify host/port - Vite will use same origin as page
|
|
// This ensures client connects to wss://app.igny8.com (port 443 implicit)
|
|
},
|
|
// Increase timeout for slow connections and dependency pre-bundling
|
|
timeout: 120000, // 120 seconds (2 minutes) to match Caddy timeout
|
|
},
|
|
}),
|
|
};
|
|
});
|