Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

webpack-bundle-size-analyzer

> 编程语言
Open source

A tool for finding out what contributes to the size of Webpack bundles

1.4K stars0 likes0 views
WebsiteGitHub

About

A tool for finding out what contributes to the size of Webpack bundles

Webpack Bundle Size Analyzer

A small utility to help you find out what is contributing to the size of your Webpack bundles.

Webpack has a JSON output mode which produces detailed machine-readable information about everything that has been included in a generated bundle.

This output is produced by running webpack --json. This tool analyzes the resulting JSON output and displays a tree of packages that were included in the bundle, ordered by the size of all the used modules.

For further reading on reducing the size of Webpack bundles, see their optimization guide

Usage

There are 2 ways to use this tool:

  1. As a command line application
  2. As a webpack plugin

CLI Usage

Assuming you have the webpack CLI command installed locally in your project:

bash
npm install -g webpack-bundle-size-analyzer
node_modules/.bin/webpack --json | webpack-bundle-size-analyzer

If you have webpack installed globally then the first part of this command will be just webpack --json instead.

When run on react-testing for example, it produces this output, where <self> refers to the size of the bundle's own code.

…

`

Plugin Usage

Description

When using the plugin version of this library, a file will be written to a location of your choice (when you run your webpack build). The file contents will be a list of the packages in your bundle (sorted in descending order). Each line will contain the name of a package, along with it's file size, and the percentage of space it takes up in your bundle.

Plugin Installation

Install this library as a development dependency to your webpack project:

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

Import your plugin at the top of your webpack.config.js file:

Old School:

javascript
var WebpackBundleSizeAnalyzerPlugin = require('webpack-bundle-size-analyzer').WebpackBundleSizeAnalyzerPlugin;

New School:

javascript
import { WebpackBundleSizeAnalyzerPlugin } from 'webpack-bundle-size-analyzer';

Now in your webpack's plugin section, start using this plugin:

javascript
{
  {...topOfConfig}
  plugins: [
    new WebpackBundleSizeAnalyzerPlugin('./reports/plain-report.txt')
  ]
  {...bottomOfConfig}
}

Example Plugin Output

Using the above plugin configuration, the following file will be written:

<webpack-output-path>/reports/plain-report.txt:

marked: 27.53 KB (14.9%)
lru-cache: 6.29 KB (3.40%)
style-loader: 717 B (0.379%)
<self>: 150.33 KB (81.3%)

Important Note About Minified Code

If you minify/compress your code using the approach recommended in the Webpack documentation, which is to use the UglifyJS plugin, be aware that this tool will report the sizes of modules before they are minified. This is because the statistics generated by webpack --json do not take account of plugins that operate on the bundle as a whole.

Knowing the sizes of dependencies before they are minified can still be useful to get an idea of how much different dependencies are responsible for size of your minified bundle, but be aware that it can be misleading. This is because some libraries compress better than others.

If instead you minify modules in your bundle individually using a loader (eg. the UglifyJS loader), the stats output by webpack --json will show minified sizes. If you want to get a better idea of the sizes of different dependencies after they are minified, you can temporarily remove the UglifyJS plugin and replace it with the UglifyJS loader instead before running webpack --json | webpack-bundle-size-analyzer.

The reason that using a plugin, rather than a loader, is the recommended approach in Webpack is that compression is better if applied to the whole bundle rather than to individual source files one at a time.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptfile-sizewebpack

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言