Packed vs Unpacked: Estimating What Your Package Weighs

There are two numbers people mean by "package size", and they answer different questions. The packed size is the compressed tarball a registry stores and a client downloads. The unpacked size is what lands on disk in node_modules or site-packages. Neither is the bundle size a browser user pays for. This page shows how to estimate both and what each one is good for.

Reading the numbers npm already gives you

Running npm pack --dry-run in a package directory prints the file list that would be published, followed by a summary. The two lines that matter look like this (values illustrative):

npm notice package size:  18.4 kB
npm notice unpacked size: 71.2 kB
npm notice total files:   23

"Package size" is the gzipped tarball. "Unpacked size" is the sum of the file sizes inside it. For Python, build the distributions with python -m build and look at the wheel and sdist in dist/; a wheel is a zip archive, so its file size is the packed figure and the total of its extracted contents is the unpacked one.

The estimate, step by step

If you want to predict the size before building, or explain to a reviewer why it jumped, break the unpacked size into its parts:

unpacked ≈ runtime_code + type_declarations + source_maps + docs_and_meta + stray_files
packed   ≈ unpacked × compression_ratio

Text such as JavaScript and Markdown compresses well with gzip, so the ratio for a code-only package is often well under one half. Already compressed assets (images, fonts, wasm) barely shrink. Treat the ratio as something you measure once on your own package, not a constant.

Worked example (illustrative)

ComponentAssumed sizeNeeded at install?
ESM and CJS builds40 kBYes
Type declarations8 kBYes, for TypeScript users
Source maps22 kBDebatable
README, LICENSE, CHANGELOG12 kBLICENSE yes; others optional
Test fixtures picked up by mistake310 kBNo

The total unpacked estimate is 392 kB, and almost four fifths of it is fixtures nobody needs. Adding a files allow-list to package.json removes them:

{
  "files": ["dist", "types", "LICENSE"]
}

npm always includes package.json, the README and the licence file regardless of this list, so you do not need to name them. Python projects get the same effect by checking what the build backend includes in the sdist and excluding fixtures in its configuration.

What these numbers do not tell you

For more ways to slim a package once you know where the weight sits, read the tips on reducing install size.