Analyze bundle size, remove/replace heavy deps until budget met.
Start the "Bundle Diet" loop. - Goal: Production bundle size is under the target budget (set in project config or default: main JS bundle < 200KB gzipped). - Max iterations: 8 - Between iterations run: `npm run build && du -sh .next/static/chunks/*.js | sort -rh | head -10` - Exit when: total JS bundle size is under the target budget. Steps: 1. Run a production build and analyze the bundle (next/bundle-analyzer, source-map-explorer, or size-limit) 2. If bundle is under budget, stop — exit condition met 3. Identify the largest contributors by size 4. For each heavy dependency, evaluate: - Can it be replaced with a lighter alternative? (moment → dayjs, lodash → native) - Can it be loaded dynamically/lazily? (next/dynamic, React.lazy) - Is it actually used, or can it be removed entirely? - Can tree-shaking be improved? (import specific modules, not the whole library) 5. Apply the highest-impact optimization 6. Rebuild and measure the size reduction 7. Repeat with the next largest contributor Self-pacing instructions: After each iteration, run the check command, read the output, and only continue if the exit condition is not met. Stop when exit condition passes or max iterations reached. Give a short status update each pass.
How it works