Careeroza
Bundle Analysis
Finding Big Dependencies
Example
npm install -D @next/bundle-analyzer
ANALYZE=true npm run buildExample output
> next build Webpack Bundle Analyzer saved report to .next/analyze/client.html Webpack Bundle Analyzer saved report to .next/analyze/nodejs.html
next.config.ts
next.config.ts
import type { NextConfig } from 'next';
import bundleAnalyzer from '@next/bundle-analyzer';
const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE === 'true' });
const nextConfig: NextConfig = {
experimental: {
optimizePackageImports: ['lucide-react', 'date-fns'], // import only the used icons/functions
},
};
export default withBundleAnalyzer(nextConfig);Tip: Next.js 16 also ships next experimental-analyze, an analyzer that works with Turbopack builds.
Usual Suspects
| Library | Lighter option |
|---|---|
moment (~300 KB) | date-fns or Intl.DateTimeFormat |
lodash (whole) | Native methods or lodash-es single imports |
| Chart library on every page | next/dynamic on the dashboard only |
| Markdown renderer in the client | Render markdown in a Server Component |