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.
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
- Real bundle size measurement — runs bundler + minifier + gzip/brotli, not raw file size on disk
- Size budgets — define limits per output file in
package.jsonor.size-limit.json; process fails when exceeded - CI blocking — non-zero exit code on limit violation blocks merges in any CI pipeline
- Bundler integrations — presets for Webpack, Rollup, esbuild, and Vite; pick the bundler that matches your stack
- Execution time reporting — estimates JS parse and execution time impact on slow hardware
- Multiple entry points — measure core, full bundle, and framework bindings separately with individual limits
- Named export measurement — use the
importfield to measure the cost of importing just one function after tree shaking - GitHub PR bot — the Size Limit Action posts a size delta table comment on every pull request automatically
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 output | Yes | No | Yes |
| Checks npm packages | No | Yes | No |
| Real tree-shaken measurement | Yes | Partial | No |
| GitHub PR bot | Yes (Action) | No | Yes |
| Execution time estimate | Yes | No | No |
| No install needed | No | Yes (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.
Related Products
on GumroadPremium Workflow Pack
Production-grade workflows, architecture guides, and deployment scripts for teams that ship. 10 advanced CI/CD workflows (blue-green, canary, E2E, security), 5 architecture deep-dives, code review checklist, PR process guide, and 5 battle-tested Bash deployment scripts.
Buy on Gumroad →GitHub Actions CI/CD Templates Pack
12 production-ready GitHub Actions workflow templates covering Node.js, Python, Docker, multi-environment deployments, security scanning, and auto-changelog. Copy, paste, ship.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →You Might Also Need
Web Performance Checklist
Interactive web performance checklist covering images, fonts, JavaScript, CSS, caching, and server. Check off items to track your score out of 100 and export as Markdown.
Open free tool →
JS Prototype Chain Visualizer
Explore JavaScript prototype chains interactively. Visualize built-in types (Array, Map, Promise, Error) and custom classes with property lookup path diagrams.
Open free tool →
JavaScript Formatter & Minifier
Format and beautify JavaScript code with proper indentation, or minify it to reduce bundle size. Handles strings, template literals, comments, and nested blocks. Runs in your browser.
Open free tool →
More Free Tools
Related Articles
Vite 6 vs Webpack 5 深度對決:2026 大型專案遷移實戰指南
2026 年最完整的 Vite 6 vs Webpack 5 深度比較與遷移指南。涵蓋效能基準測試、分塊策略、CSS Modules、環境變數轉換、常見陷阱與真實大型專案遷移清單。
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.
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.
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.
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.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →