feat: optimize vite chunks#651
Conversation
📝 WalkthroughWalkthroughThe pull request adds bundle visualization and optimizes code-splitting in the frontend build configuration. Changes include a new rollup-plugin-visualizer dependency, updated gitignore for generated stats files, and Vite configuration updates to split vendor code into separate chunks for React, Radix UI, i18next, and Zod. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #651 +/- ##
=======================================
Coverage 15.96% 15.96%
=======================================
Files 48 48
Lines 3515 3515
=======================================
Hits 561 561
Misses 2897 2897
Partials 57 57 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
frontend/vite.config.ts (1)
9-9: Consider running the visualizer only during analysis builds.
visualizer()is included unconditionally, so it runs on every production build and emitsstats.html. This adds a small overhead and produces an artifact that's typically only needed during bundle analysis. You could gate it behind an env variable or Vite mode.Example
- plugins: [react(), tailwindcss(), visualizer()], + plugins: [ + react(), + tailwindcss(), + ...(process.env.ANALYZE ? [visualizer({ open: true })] : []), + ],🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/vite.config.ts` at line 9, The visualizer plugin is being added unconditionally (plugins: [react(), tailwindcss(), visualizer()]) which emits stats.html on every build; change the Vite config to include visualizer() only when enabled (e.g., process.env.ANALYZE === 'true' or config.mode === 'analyze'): create a conditional visualizerPlugin variable (null when disabled, visualizer() when enabled) and spread/filter it into the plugins array (e.g., const plugins = [react(), tailwindcss(), ...(visualizerPlugin ? [visualizerPlugin] : [])] or plugins.filter(Boolean)) so production builds skip the visualizer unless explicitly requested.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/vite.config.ts`:
- Around line 18-37: The manualChunks check for React is too broad: replace the
loose id.includes("/react") check in manualChunks with a precise match for core
React packages (e.g., only match node_modules paths for "react" and "react-dom"
using a regex that looks for /node_modules\/(react|react-dom)([\\/]|$)) so other
packages like react-i18next fall through to their specific checks
(vendor-i18next) and don't get lumped into vendor-react; also gate the
visualizer() plugin so it only runs for analysis/dev builds (e.g., only include
visualizer() when an ANALYZE env var or build mode flag is set) to avoid running
it unconditionally.
---
Nitpick comments:
In `@frontend/vite.config.ts`:
- Line 9: The visualizer plugin is being added unconditionally (plugins:
[react(), tailwindcss(), visualizer()]) which emits stats.html on every build;
change the Vite config to include visualizer() only when enabled (e.g.,
process.env.ANALYZE === 'true' or config.mode === 'analyze'): create a
conditional visualizerPlugin variable (null when disabled, visualizer() when
enabled) and spread/filter it into the plugins array (e.g., const plugins =
[react(), tailwindcss(), ...(visualizerPlugin ? [visualizerPlugin] : [])] or
plugins.filter(Boolean)) so production builds skip the visualizer unless
explicitly requested.
Summary by CodeRabbit