Calculate the size of your npm package distribution
⚡️ Try it in your npm package
$ npx pkg-size
- 🔍 Size analysis Quickly determine the total size of what you're publishing to npm!
- 🔥 Same behavior as npm
pack
/publish
Collects publish files as specified in yourpackage.json
! - 🙌 Gzip & Brotli See how your files compress in addition to normal size!
- 🤖 Node.js API Integrate size checks to your 8000 CI via Node.js API
Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️
To quickly determine the uncompressed size, gzip size, and brotli size of your package before publishing it to npm.
npm i pkg-size
pkg-size ./package/path
pkg-size --sizes=size,gzip
pkg-size --sort-by=name
Use IEC units (insted of metric) for size
pkg-size --unit=iec
Comma separated list of sizes to show (size, gzip, brotli) (default: size,gzip,brotli)
Sort list by (name, size, gzip, brotli) (default: brotli)
Display units (metric, iec, metric_octet, iec_octet) (default: metric)
Glob to ignores files from list. Total size will still include them.
JSON output
Display this message
Display version number
const pkgSize = require('pkg-size');
// Get the package size of the current working directory
const sizeData = await pkgSize();
// ... Or get the package size of a specific package path
const sizeData = await pkgSize('/path/to/package');
type FileEntry = {
path: string;
size: number;
sizeGzip: number;
sizeBrotli: number;
};
type PkgSizeData = {
pkgPath: string;
tarballSize: number;
files: FileEntry[];
};
function pkgSize(pkgPath?: string): Promise<PkgSizeData>;
A GitHub Action to automate package size regression reports on your pull requests—great for size-conscious development.