Skip to main content

Size Limit

Performance budget tool for JavaScript. Measures the real minified and gzipped bundle size of your library or app, blocks CI when limits are exceeded, and posts an automated size delta comment on every pull request via the GitHub bot.

✓ Real gzip/brotli size ✓ Size budgets in config ✓ CI blocking ✓ Webpack / esbuild / Rollup ✓ GitHub PR bot ✓ Execution time impact

What is Size Limit?

Size Limit is an open-source tool created by Andrey Sitnik (the author of PostCSS and Nano ID) that brings performance budgets to JavaScript projects. It integrates into your build pipeline, measures each output file's real compressed size, and fails the process if any file exceeds its configured limit. This turns bundle size from a metric you check occasionally into a hard constraint enforced on every commit.

Unlike tools that just report file size on disk, Size Limit runs your output through a bundler, applies tree shaking, minifies the result, and compresses it — matching what a browser actually downloads. It also estimates JavaScript execution time on a slow 3G connection, surfacing the full performance cost of shipping more code.

Key Features

Installation

# Install Size Limit and a preset for your bundler
npm add -D size-limit @size-limit/preset-small-lib

# Other common presets:
# @size-limit/preset-app          — for web apps (uses esbuild)
# @size-limit/preset-big-lib      — for larger libraries
# @size-limit/preset-small-lib    — for small libraries (no peer deps)

# Run Size Limit
npx size-limit

# Run with JSON output (useful for CI comparisons)
npx size-limit --json

Setting Up Size Budgets

Add a size-limit array to package.json with a path and limit per output file. Run npx size-limit after your build step.

// package.json — add a size-limit config section and a script
{
  "name": "my-ui-library",
  "version": "1.0.0",
  "scripts": {
    "build": "tsup src/index.ts",
    "size": "npm run build && size-limit",
    "analyze": "npm run build && size-limit --why"
  },
  "size-limit": [
    {
      "path": "dist/index.js",
      "limit": "10 kB"
    },
    {
      "path": "dist/index.esm.js",
      "limit": "10 kB"
    }
  ]
}

// Running: npm run size
//
// Package size: dist/index.js
//
//   Size limit:  10 kB
//   Size:         8.1 kB with all dependencies, minified and gzipped
//
//   Time limit:   50 ms
//   Time:         32 ms   on slow 3G
//
// Package size: dist/index.esm.js
//
//   Size limit:  10 kB
//   Size:         7.9 kB with all dependencies, minified and gzipped

Multiple Entry Points

Libraries with separate entry points can define individual limits for each. The import field lets you measure the tree-shaken cost of importing only a specific named export.

// size-limit config for a library with multiple entry points
// .size-limit.json
[
  {
    "name": "Core module",
    "path": "dist/core.js",
    "limit": "5 kB",
    "import": "{ createStore }"
  },
  {
    "name": "Full bundle",
    "path": "dist/index.js",
    "limit": "20 kB"
  },
  {
    "name": "React bindings",
    "path": "dist/react.js",
    "limit": "3 kB",
    "import": "{ useStore }",
    "peerDependencies": false
  }
]

// The "import" field measures the size of just that named export
// after tree shaking — useful for libraries that allow partial imports.

CI Integration and GitHub PR Bot

The Size Limit GitHub Action automatically builds both the base branch and the PR branch, compares sizes, and posts a comment table showing the delta for each entry point. No manual steps needed from developers — size changes are visible in every PR review.

# .github/workflows/size-limit.yml
# Uses the Size Limit Action to post a comment on every PR
# showing the bundle size delta (before vs after your changes).

name: Size Limit Check

on:
  pull_request:

jobs:
  size:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci

      - name: Size Limit Report
        uses: andresz1/size-limit-action@v1
        with:
          github_token: secrets.GITHUB_TOKEN
          # The action builds your project, compares sizes to the base
          # branch, and posts a comment table like:
          #
          # | Path           | Size    | Change  | Limit  |
          # |----------------|---------|---------|--------|
          # | dist/index.js  | 8.1 kB  | +0.2 kB | 10 kB  | OK
          # | dist/react.js  | 2.8 kB  | -0.1 kB |  3 kB  | OK

Analyzing What's Inside

When Size Limit reports a size you do not expect, use --why to open an interactive bundle analyzer treemap showing which modules contribute most to the final size.

# Use --why to open a bundle analyzer and see what is inside
npm run build && npx size-limit --why

# Size Limit integrates with:
# - Webpack Bundle Analyzer (if using Webpack preset)
# - esbuild Bundle Analyzer (if using esbuild preset)
#
# This shows a treemap of every module contributing to the final bundle,
# helping you identify large dependencies worth replacing or lazy-loading.
#
# Common findings:
#   - date-fns pulling in all locales instead of just one
#   - lodash imported as a full bundle instead of individual methods
#   - a polyfill included unnecessarily for a modern target
#   - duplicate packages at different versions (e.g. two copies of React)

Size Limit vs Bundlephobia vs bundlesize

Feature Size Limit Bundlephobia bundlesize
Measures your own outputYesNoYes
Checks npm packagesNoYesNo
Real tree-shaken measurementYesPartialNo
GitHub PR botYes (Action)NoYes
Execution time estimateYesNoNo
No install neededNoYes (online)No

Pros and Cons

Pros

  • ✓ Measures real compressed size, not misleading raw file size
  • ✓ Hard CI blocking prevents accidental size regressions from shipping
  • ✓ GitHub PR bot makes size visible in every code review automatically
  • ✓ Supports Webpack, esbuild, Rollup, and Vite via swappable presets
  • ✓ Named export measurement shows tree-shaken cost of individual functions
  • ✓ --why opens bundle analyzer to pinpoint large dependencies

Cons

  • ✗ Requires a build step before measuring — not instant feedback
  • ✗ Preset selection can be confusing for projects not using a standard bundler
  • ✗ Only measures output files you configure — easy to miss a new entry point
  • ✗ CI build time increases (builds project twice for PR delta comparisons)
  • ✗ Does not check third-party npm package costs (use Bundlephobia for that)

Frequently Asked Questions

What is Size Limit?▼

Size Limit is a performance budget tool for JavaScript libraries and applications. You define size limits in your project config, and Size Limit measures the real bundle size — after minification and gzip/brotli compression — then fails your build or CI check if any limit is exceeded. It also shows JavaScript execution time impact, helping you catch performance regressions before they ship to users.

How does Size Limit measure bundle size?▼

Size Limit does not simply report file size on disk. It runs your output through a real bundler (Webpack, Rollup, or esbuild depending on the preset), applies tree shaking to remove unreachable code, minifies the result, and then compresses it with gzip or brotli. This produces a number that closely matches what a user's browser actually downloads, making it a much more accurate performance signal than raw file size.

How do I set up size budgets?▼

Add a size-limit array to your package.json (or a .size-limit.json file). Each entry has a path glob matching your build output and a limit string like '10 kB'. When you run npx size-limit, it builds your project and measures each entry. If any entry exceeds its limit, the process exits with a non-zero code, blocking CI merges. You can also use the import field to measure the cost of importing just a specific named export after tree shaking.

How does CI integration work?▼

Size Limit exits with a non-zero exit code when a limit is exceeded, so any CI pipeline running npx size-limit as a step will fail automatically. For pull request workflows, the andresz1/size-limit-action GitHub Action takes this further: it builds both the base branch and the PR branch, compares the sizes, and posts a comment table on the PR showing the size delta for each entry point. This gives reviewers immediate visibility into bundle size changes without any manual work.

What is the GitHub PR bot?▼

The Size Limit GitHub Action (andresz1/size-limit-action) posts an automated comment on every pull request that shows a table comparing bundle sizes between the base branch and the PR branch. Each row shows the path, current size, size change (with a + or - delta), and whether the limit is still met. This makes bundle size a visible part of every code review without requiring developers to run anything locally.

How does Size Limit compare to Bundlephobia?▼

Size Limit and Bundlephobia serve different purposes. Size Limit is a local CLI tool you add to your project's build pipeline to enforce size budgets on your own code — it measures your output files and blocks CI if limits are exceeded. Bundlephobia is a public online service for checking the bundle cost of third-party npm packages before you install them. Use Bundlephobia when evaluating a new dependency, and use Size Limit to continuously enforce the total size of what you ship.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Related Articles

Apr 5, 2026 · 16 min read

Vite 6 vs Webpack 5 深度對決:2026 大型專案遷移實戰指南

2026 年最完整的 Vite 6 vs Webpack 5 深度比較與遷移指南。涵蓋效能基準測試、分塊策略、CSS Modules、環境變數轉換、常見陷阱與真實大型專案遷移清單。

Apr 2, 2026 · 13 min read

Node.js 22 Performance Guide: Worker Threads, Cluster Mode, and V8 Optimizations

Maximize Node.js 22 performance with Worker Threads for CPU-bound tasks, Cluster mode for multi-core utilization, V8 optimization tips, profiling tools, and memory management best practices.

Apr 2, 2026 · 25 min read

Performance Optimization 2026: Complete Guide to Frontend, Backend, and Infrastructure

Comprehensive performance optimization guide for 2026 covering Core Web Vitals, JavaScript bundle optimization, server-side rendering, caching strategies, database query optimization, CDN configuration, and real-world benchmarks.

Apr 2, 2026 · 14 min read

React Hooks Deep Dive: useEffect, useMemo, useCallback Performance Guide

Complete guide to React hooks performance in 2025. Master useEffect lifecycle patterns, useMemo vs useCallback differences, and when each hook helps or hurts performance.

Apr 2, 2026 · 20 min read

Rust and WebAssembly in 2026: From Zero to Production

Learn how to compile Rust code to WebAssembly for blazing-fast web applications. A complete guide covering wasm-pack, wasm-bindgen, web-sys, JavaScript integration, performance optimization, and real-world case studies from Figma, Google Earth, and more.

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →