Skip to content

Measure the size of your npm package distribution

License

Notifications You must be signed in to change notification settings

pkg-size/pkg-size

Repository files navigation







Calculate the size of your npm package distribution

⚡️ Try it in your npm package

$ npx pkg-size

Features

  • 🔍 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 your package.json!
  • 🙌 Gzip & Brotli See how your files compress in addition to normal size!
  • 🤖 Node.js API Integrate size checks to your 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! ❤️

🙋‍♂️ Why?

To quickly determine the uncompressed size, gzip size, and brotli size of your package before publishing it to npm.

🚀 Install

npm i pkg-size

🚦 Quick Usage

Get the package size by package path

pkg-size ./package/path

Skip brotli size calculation

pkg-size --sizes=size,gzip

Order files by name

pkg-size --sort-by=name

Use IEC units (insted of metric) for size

pkg-size --unit=iec

⚙️ CLI Options

-S, --sizes

Comma separated list of sizes to show (size, gzip, brotli) (default: size,gzip,brotli)

-s, --sort-by

Sort list by (name, size, gzip, brotli) (default: brotli)

-u, --unit

Display units (metric, iec, metric_octet, iec_octet) (default: metric)

-i, --ignore-files

Glob to ignores files from list. Total size will still include them.

--json

JSON output

-h, --help

Display this message

-v, --version

Display version number

👷‍♂️ Node.js API

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');

Interface

type FileEntry = {
    path: string;
    size: number;
    sizeGzip: number;
    sizeBrotli: number;
};

type PkgSizeData = {
    pkgPath: string;
    tarballSize: number;
    files: FileEntry[];
};

function pkgSize(pkgPath?: string): Promise<PkgSizeData>;

👨‍👩‍👦 Related

A GitHub Action to automate package size regression reports on your pull requests—great for size-conscious development.