From 0fb2a53a4f0dc9c55556b0181b503a4510cece8d Mon Sep 17 00:00:00 2001 From: curo1305 Date: Tue, 16 Jun 2026 21:04:54 +0200 Subject: [PATCH] chore(11-01): add ANALYZE=true opt-in for rollup-plugin-visualizer in vite.config.js - Wrapped config in async defineConfig factory so visualizer can be dynamically imported only when ANALYZE=true; normal builds incur zero overhead - Added frontend/stats.html to .gitignore (ephemeral artifact; canonical copy lives in .planning/perf/) --- .gitignore | 1 + frontend/vite.config.js | 46 +++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index eb2f5c8..2fdb90b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ backend/data/ frontend/node_modules/ frontend/dist/ frontend/package-lock.json +frontend/stats.html screenshots/ diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 7d0bf9e..b78a252 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,20 +1,36 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' -export default defineConfig({ - plugins: [vue()], - build: { - // top-level await in main.js requires esnext target - target: 'esnext', - }, - server: { - host: '0.0.0.0', - port: 5173, - proxy: { - '/api': { - target: 'http://backend:8000', - changeOrigin: true, +// Bundle analyzer: only active when ANALYZE=true is set in the environment. +// Usage: ANALYZE=true npm run build +// Output: stats.html in the project root (committed to .planning/perf/ manually). +function conditionalAnalyzer(env) { + if (env.ANALYZE !== 'true') return null + // Dynamic import so the package is never executed during normal builds. + return import('rollup-plugin-visualizer').then(({ visualizer }) => + visualizer({ open: false, filename: 'stats.html', gzipSize: true }) + ) +} + +export default defineConfig(async ({ mode }) => { + const env = loadEnv(mode, process.cwd(), '') + const analyzerPlugin = await conditionalAnalyzer(env) + + return { + plugins: [vue(), ...(analyzerPlugin ? [analyzerPlugin] : [])], + build: { + // top-level await in main.js requires esnext target + target: 'esnext', + }, + server: { + host: '0.0.0.0', + port: 5173, + proxy: { + '/api': { + target: 'http://backend:8000', + changeOrigin: true, + }, }, }, - }, + } })