Scripts2026年7月28日·1 分钟阅读

Bundlephobia — Find the Cost of Adding a npm Package

A web tool and API that shows the bundle size impact of any npm package before you install it. Check minified size, gzipped size, download time, and composition of any dependency.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Bundlephobia
先审查命令
npx -y tokrepo@latest install cd2319cb-8aa2-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

Bundlephobia helps JavaScript developers understand the real cost of adding a dependency to their project. It shows the minified size, gzipped size, download time, and dependency tree of any npm package, so you can make informed decisions about what to include in your bundle.

What Bundlephobia Does

  • Displays minified and gzipped bundle sizes for any npm package
  • Shows estimated download times on slow 3G, emerging 4G, and average connections
  • Breaks down the dependency tree to show which sub-dependencies add weight
  • Compares sizes across versions to track package bloat over time
  • Provides a public API for programmatic size lookups

Architecture Overview

Bundlephobia runs a Node.js backend that installs each queried package in an isolated environment, bundles it with webpack, and measures the output size. Results are cached so subsequent lookups for the same package version return instantly. The frontend is a lightweight web app that queries the API and renders size visualizations.

Self-Hosting & Configuration

  • Clone the repository: git clone https://github.com/pastelsky/bundlephobia
  • Install dependencies: yarn install
  • Start the development server: yarn dev
  • The app requires Node.js and webpack installed locally for bundling analysis
  • Configure caching backends and rate limits via environment variables

Key Features

  • Instant size analysis for the entire npm registry
  • Historical size tracking across package versions
  • Dependency composition breakdown showing which imports add weight
  • Export analysis support showing individual named export costs
  • Badge generator for embedding size info in README files

Comparison with Similar Tools

  • webpack-bundle-analyzer — Analyzes your actual build output; Bundlephobia checks packages before install
  • size-limit — CI tool to enforce bundle budgets; Bundlephobia is a lookup service
  • Import Cost (VS Code extension) — Shows import size inline in your editor; Bundlephobia is web-based
  • packagephobia — Measures install size (disk space); Bundlephobia measures bundle size (what ships to users)

FAQ

Q: Does Bundlephobia account for tree-shaking? A: The default size shown is the entire package. For packages that support ES modules, Bundlephobia also shows the size of individual named exports.

Q: Can I check private packages? A: No. Bundlephobia only works with packages published to the public npm registry. For private packages, use size-limit locally.

Q: How accurate are the size numbers? A: Bundlephobia uses webpack to create a real production bundle, so numbers closely match what you would ship. Minor differences may occur due to your specific webpack or Rollup configuration.

Q: Is there a CLI tool? A: Community tools like bundle-phobia-cli provide command-line access to the Bundlephobia API.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产