JavaScript Bundle Analysis Tools: Find Duplicate Dependencies and Track Build Size
JavaScriptfrontend performancebundlerswebpackVitenpm dependencies

JavaScript Bundle Analysis Tools: Find Duplicate Dependencies and Track Build Size

WWebbclass Editorial Team
2026-11-20
7 min read

Compare JavaScript bundle analysis tools and use a repeatable workflow to find duplicate dependencies, verify tree shaking, and track build size.

JavaScript bundle analysis tools show which files, packages, and application routes are making a production build large. This guide compares the main analysis approaches, explains a repeatable workflow for finding duplicate dependencies and missed tree shaking, and provides a simple method for recording bundle-size changes before they reach users.

Overview

A large JavaScript bundle is rarely caused by one obvious file. The total may include application code, framework code, third-party packages, polyfills, source-map references, CSS extracted by the build, and assets loaded by particular routes. A useful JavaScript bundle analyzer turns that output into a report you can inspect rather than treating the final file size as a mystery.

The right tool depends on the question you are asking:

Analysis approachBest forWhat to inspect
Source-map explorerConnecting production output to source files and packagesWhich modules occupy the most mapped space
Bundler analyzerUnderstanding chunks, modules, and import pathsChunk composition, shared modules, and unexpectedly included code
Browser coverage reportChecking code delivered but not used during a test sessionUnused bytes on specific pages and interactions
CI size-budget toolPreventing regressions during pull requests and releasesBefore-and-after changes against defined limits
Dependency visualizerFinding duplicate package versions and dependency relationshipsRepeated packages, transitive dependencies, and heavy branches

These tools answer different parts of the same problem. A dependency tree can show that two versions of a package are installed, while a bundle report shows whether both versions actually reach the browser. A coverage report can identify unused code on one route, but it does not prove that the code is unnecessary on every route. Use reports together and keep the production build as the baseline.

How to estimate bundle impact

Start by choosing a measurement that matches the decision you need to make. For a broad release review, record the total compressed transfer size and the uncompressed JavaScript size. For a route-level investigation, record the initial JavaScript for that route and the chunks loaded after a representative interaction. Keep these measurements separate: a smaller raw file is not automatically a smaller network transfer, and a smaller transfer is not necessarily faster if it delays important execution.

Use this simple calculation for a before-and-after comparison:

Change in size = new measured size − old measured size

Percentage change = (new measured size − old measured size) ÷ old measured size × 100

For example, if a route's initial JavaScript changes from 420 KB to 465 KB under the same build and measurement conditions, the increase is 45 KB, or approximately 10.7%. The calculation does not decide whether the change is acceptable. It gives the team a consistent signal to investigate.

To make the comparison useful, generate a production build with the same configuration for both versions. Use the same package lockfile policy, environment variables where they affect bundling, minification settings, and entry route. Store the report as a build artifact or commit the key measurements to a small release log. If your bundler supports an analysis plugin or report command, use the version-compatible instructions for that bundler rather than copying a command from an older project.

For webpack projects, a bundle analyzer can produce a treemap or statistics report from the production compilation. For Vite projects, use a plugin or compatible Rollup analysis workflow to inspect generated chunks. The exact installation and command may change with the project’s framework and tool versions, so treat the configuration file and official tool documentation as the source of truth.

Inputs and assumptions

A bundle-size estimate is only meaningful when its inputs are recorded. At minimum, capture:

  • Build target: the application, route, entry point, and deployment mode being measured.
  • Toolchain: bundler, framework, JavaScript runtime, minifier, and relevant plugin versions.
  • Dependency state: the lockfile revision and whether optional or peer dependencies changed.
  • Size metric: raw bytes, compressed bytes, initial-load bytes, or all generated chunks.
  • Loading scenario: the page and interactions used when collecting browser coverage.
  • Comparison point: the previous release, main branch, or a known good build.

When investigating a large bundle, first separate application code from vendor code and route-specific chunks. This prevents a framework or shared library from being blamed for a change caused by a new feature. Then look for repeated package names or similar paths in the report. Duplicate dependencies can appear when different packages require incompatible versions, when import paths resolve differently, or when equivalent libraries are included through separate entry points.

Check tree shaking with care. A package may appear in the output because an import is not statically analyzable, because the package declares side effects, because a CommonJS build is being consumed, or because the application genuinely uses the code. Do not remove an import solely because a coverage report marks it unused in one test session. Confirm the route, interaction, and supported browsers before changing behavior.

For a complementary dependency review, see the NPM dependency update workflow. Dependency maintenance and bundle analysis work best together: the lockfile identifies what changed, while the production report shows what reached users.

Worked examples

Example 1: A new package increases the main chunk

A team adds a date or charting package and sees the main chunk increase. The analyzer shows the new package in the initial entry rather than a route-level chunk. First, check whether the feature is needed during initial rendering. If it is only used on a secondary screen, move the import behind the route or component boundary using the framework’s supported lazy-loading pattern. Rebuild and compare the initial chunk and the deferred chunk separately. The total application bytes may not change much, but the first route can become smaller.

Example 2: Two versions of a package are present

A dependency visualizer shows two versions of the same utility library. Inspect the dependency tree to identify which top-level packages request each version. If the versions are compatible, a controlled upgrade or resolution strategy may consolidate them. If they are not compatible, do not force a resolution without testing. Re-run the bundle analyzer afterward: removing a duplicate from the install tree does not guarantee that the browser bundle will shrink if only one version was included in the relevant entry.

Example 3: Coverage reports show unused code

Browser coverage marks a large portion of a shared chunk as unused on the home page. Repeat the test on the important routes and with normal user interactions. If the same code is unused across the initial experience, consider splitting the chunk or changing the import boundary. If it is used later, the result may be an intentional trade-off. Record the test scenario alongside the result so another developer can reproduce it.

Example 4: Add a CI size budget

Choose a small set of metrics, such as initial JavaScript for key routes and the total compressed output. Establish a baseline from a reviewed production build. Configure CI to report the difference on every relevant change, and decide in advance whether a threshold should block merging or merely request review. A budget is most useful when an exception includes a reason, an owner, and a follow-up date. Otherwise, gradual increases can become the new baseline without a clear decision.

When to recalculate

Re-run bundle analysis after dependency upgrades, framework or bundler changes, route changes, new shared components, build-configuration edits, and changes to code-splitting boundaries. Also review it during release preparation when a feature adds a large client-side library, changes rendering behavior, or introduces a new browser integration.

Keep a lightweight record containing the build identifier, tool versions, key size metrics, analyzer report, and a short explanation of meaningful changes. Recalculate after resolving a regression rather than relying on the intended result. A package may be removed from source code but remain in another entry, or a configuration change may alter chunking in an unexpected way.

For a practical workflow, create a repeatable checklist:

  1. Install from the locked dependency state.
  2. Generate a production build using the project’s documented configuration.
  3. Inspect chunk composition with a bundler or source-map analyzer.
  4. Compare the dependency tree for duplicate versions.
  5. Use browser coverage on representative routes and interactions.
  6. Record raw and compressed measurements against the previous baseline.
  7. Open a focused change, rebuild, and verify that the report confirms the improvement.

Bundle analysis is most effective as a recurring development habit, not a one-time cleanup exercise. Pair it with API and publishing checks where appropriate—for example, the OpenAPI linting guide can help keep backend contract changes from creating avoidable frontend work. When the inputs change, repeat the measurement, explain the difference, and preserve the comparison for the next release review.

Related Topics

#JavaScript#frontend performance#bundlers#webpack#Vite#npm dependencies
W

Webbclass Editorial Team

Technical Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.