Bundle Size Numbers: Which One to Measure and Where It Comes From
"How big is this package?" has at least four correct answers, and they can differ by an order of magnitude. If you publish a front-end library, you should know which number your users care about, how to produce it reproducibly, and how to stop it creeping up release after release.
The four sizes
- Tarball size
- The compressed archive the registry stores.
npm pack --dry-runprints it together with the file list, and it is the fastest way to notice that you accidentally shipped your test fixtures. - Install size
- Everything that lands in
node_modules, including transitive dependencies. It matters for CI time and serverless deploy limits. Tools such as packagephobia report it. - Bundle size
- What ends up in a browser bundle when someone imports your package with a typical bundler, usually reported minified and gzipped. bundlephobia is the best-known public reporter.
- Imported size
- The bundle cost of the specific functions a user imports, after tree-shaking. For a well-structured library this is the number that should be small.
Producing the numbers yourself
Third-party sites are convenient but not reproducible on your own branch. Measure in your repository instead. A minimal setup with the size-limit tool looks like this:
// package.json (excerpt)
{
"scripts": { "size": "size-limit" },
"size-limit": [
{ "path": "dist/index.js", "import": "{ parse }", "limit": "4 kB" },
{ "path": "dist/index.js", "limit": "12 kB" }
]
}
The first entry measures the cost of importing a single named export; the second measures the whole entry point. The limits above are placeholders; set yours from a measured baseline. If you build with esbuild, its metafile output gives a per-module breakdown that shows exactly which source file grew.
Things that skew the result
- Which bundler and settings. Results differ between bundlers and minifiers. Pin the tool versions you measure with.
- Compression algorithm. gzip and brotli give different numbers. State which one you report.
- Peer dependencies. If a framework is a peer dependency, decide whether you include it. Usually you should not, because the app already pays for it.
- Side effects. A missing or wrong
"sideEffects"field can make an entire module survive tree-shaking. Our sideEffects Q&A covers this.
Which number to put in your README
Users comparing libraries mostly want one figure: what it costs to import the thing they need. If your package is tree-shakeable, quote the imported size of the most common entry function alongside the full entry point, and name the bundler and compression you used. If it is not tree-shakeable, say so honestly and quote the full minified and gzipped size. Avoid quoting the unminified source size; it flatters nobody and confuses comparisons. Whatever you pick, generate it from the same script that runs in CI so the README never drifts from reality.
Tracking it over time
A size number is most useful as a trend. Run the size check on every pull request and fail the build when a limit is exceeded, so growth becomes a conscious decision rather than an accident. Record the measured figure in the changelog for releases that change it significantly. And when you do grow, say why: a new feature that costs two kilobytes is an easy trade for most users if they know about it.