854c4b91a8
Audited the renderer bundle with rollup-plugin-visualizer. Top offenders (libsodium-sumo 292KB gz, livekit-client 177KB gz, @supabase 149KB gz) all have justified usage and no viable swap. Mediapipe + track-processors are already lazy-loaded into a separate chunk on first BackgroundBlur activation. Bundle has zero duplicate packages, no moment/lodash/dayjs, no syntax-highlight libs, no polyfills — already lean from T1+T6. Added rollup-plugin-visualizer as a dev-dep, gated behind ANALYZE=true so production builds pay no cost. Run with: ANALYZE=true pnpm --filter @chat-app/desktop build to regenerate stats.html (treemap) + stats.json (raw) for future audits.
117 lines
3.8 KiB
TypeScript
117 lines
3.8 KiB
TypeScript
// electron-vite config. Three targets:
|
|
// - main: the Electron main-process entry (electron/main.ts)
|
|
// - preload: the contextBridge script (electron/preload.ts)
|
|
// - renderer: the existing React app at apps/desktop/ (unchanged root)
|
|
//
|
|
// Manual chunks + optimizeDeps config is ported from the pre-migration
|
|
// vite.config.ts so LiveKit/libsodium/supabase/react vendor bundles keep
|
|
// caching independently across app updates.
|
|
|
|
import react from '@vitejs/plugin-react';
|
|
import { defineConfig, externalizeDepsPlugin } from 'electron-vite';
|
|
import path from 'node:path';
|
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
|
|
const ANALYZE = process.env.ANALYZE === 'true';
|
|
|
|
const rendererAliases = {
|
|
'@': path.resolve(__dirname, './src'),
|
|
'@shared': path.resolve(__dirname, '../../packages/shared/src'),
|
|
'@db-types': path.resolve(__dirname, '../../packages/db-types/src'),
|
|
'@ui-web': path.resolve(__dirname, '../../packages/ui-web/src'),
|
|
};
|
|
|
|
export default defineConfig({
|
|
main: {
|
|
plugins: [externalizeDepsPlugin()],
|
|
build: {
|
|
outDir: 'out/main',
|
|
rollupOptions: {
|
|
input: path.resolve(__dirname, 'electron/main.ts'),
|
|
},
|
|
},
|
|
},
|
|
preload: {
|
|
plugins: [externalizeDepsPlugin()],
|
|
build: {
|
|
outDir: 'out/preload',
|
|
rollupOptions: {
|
|
input: path.resolve(__dirname, 'electron/preload.ts'),
|
|
},
|
|
},
|
|
},
|
|
renderer: {
|
|
root: '.',
|
|
// file:// loading from inside app.asar can't resolve root-absolute
|
|
// asset URLs (`/assets/...`) — they hit the OS root instead of the
|
|
// bundle. Relative base produces `./assets/...` which works in both
|
|
// dev (served from /) and packaged builds.
|
|
base: './',
|
|
// Visualizer plugins are gated behind ANALYZE=true so the production
|
|
// build never pays the analysis cost. Re-enable with:
|
|
// ANALYZE=true pnpm --filter @chat-app/desktop build
|
|
// which writes apps/desktop/stats.html (treemap) + stats.json (raw).
|
|
plugins: [
|
|
react(),
|
|
...(ANALYZE
|
|
? [
|
|
visualizer({
|
|
filename: 'stats.html',
|
|
template: 'treemap',
|
|
gzipSize: true,
|
|
brotliSize: true,
|
|
open: false,
|
|
}),
|
|
visualizer({
|
|
filename: 'stats.json',
|
|
template: 'raw-data',
|
|
gzipSize: true,
|
|
brotliSize: true,
|
|
}),
|
|
]
|
|
: []),
|
|
],
|
|
resolve: {
|
|
alias: rendererAliases,
|
|
},
|
|
optimizeDeps: {
|
|
// libsodium-wrappers-sumo (and the compact variant) ship broken
|
|
// "import" conditions in package exports — the ESM bundle
|
|
// references a sibling ./libsodium.mjs that isn't in the
|
|
// published artefact. Force esbuild to pick the "require"
|
|
// condition so the self-contained CJS build is used.
|
|
include: ['libsodium-wrappers-sumo'],
|
|
esbuildOptions: {
|
|
conditions: ['require', 'node', 'default'],
|
|
},
|
|
},
|
|
build: {
|
|
outDir: 'out/renderer',
|
|
rollupOptions: {
|
|
input: path.resolve(__dirname, 'index.html'),
|
|
output: {
|
|
manualChunks: (id: string): string | undefined => {
|
|
if (id.includes('node_modules/livekit-client')) return 'vendor-livekit';
|
|
if (id.includes('node_modules/libsodium-wrappers-sumo'))
|
|
return 'vendor-sodium';
|
|
if (id.includes('node_modules/@supabase')) return 'vendor-supabase';
|
|
if (
|
|
id.includes('node_modules/react-router') ||
|
|
id.includes('node_modules/react-dom') ||
|
|
id.includes('node_modules/react/')
|
|
) {
|
|
return 'vendor-react';
|
|
}
|
|
return undefined;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
port: 1420,
|
|
strictPort: true,
|
|
},
|
|
clearScreen: false,
|
|
},
|
|
});
|