Course contentsShow
← React
Lesson 1402 of 2,39635. Code SplittingFree lesson

Route-Based Bundle Analysis

Using bundle analyzer to verify route chunks are properly split and identifying routes that pull in unexpected dependencies.

Route-Based Bundle Analysis

What you'll learn: How to use bundle analysis tools to confirm your routes are actually splitting correctly and catch unexpected dependencies bloating your chunks.

Why Analyze Route Bundles?

You've implemented code splitting, wrapped routes in React.lazy(), and everything seems fine. But are your bundles actually split the way you think? Route-based bundle analysis is like looking under the hood—it reveals what code actually ends up in each chunk file, verifying your splitting strategy worked and identifying surprises.

Using Bundle Analyzer Tools

The most popular tool is webpack-bundle-analyzer. After building your app, it creates an interactive treemap showing every chunk and what's inside:

npm install --save-dev webpack-bundle-analyzer

Run your production build, then visualize it. You'll see each route chunk as a separate box, with the modules inside each one.

What to Look For

Verify proper splits: Each lazy-loaded route should appear as its own chunk file. If two routes appear in the same chunk, your React.lazy() setup might be incorrect.

Identify unexpected dependencies: You split AdminDashboard expecting a small chunk, but the analyzer shows it's 800KB. Turns out it imports moment.js for a single date format—an unexpected heavyweight pulling along for the ride.

Find shared dependencies: The analyzer reveals that three route chunks all include lodash. This signals an opportunity to extract common code into a shared chunk.

Catch duplicate dependencies: Sometimes the same library appears in multiple chunks at different versions—a sign of dependency misalignment.

The Detective Work

Bundle analysis is detective work. You're looking for: routes that are heavier than expected, libraries appearing where they shouldn't, and opportunities to optimize further.

Key Takeaway: Bundle analyzers transform invisible splitting decisions into visible data, letting you verify route chunks are correctly isolated and hunt down the dependencies inflating your bundle sizes.