Know the cost of every import before you ship.
Import Cost displays the bundle size of imported packages inline in your editor. It scans your imports, bundles each one with esbuild, and shows the minified, gzipped, and brotli-compressed size — right next to the import statement.
import { debounce } from 'lodash'; // 72.1 KB (gzip: 25.3 KB) · shared 4 files
import { format } from 'date-fns'; // 12.4 KB (gzip: 4.1 KB)
import express from 'express'; // 783 KB (gzip: 261 KB) — try named imports| Package | Description | Version |
|---|---|---|
import-cost-core |
Core library and CLI | |
fast-import-cost |
VS Code extension | |
coc-import-cost-fast |
coc.nvim extension |
- Inline size decorations — see the cost of every
importandrequireas you type - Workspace-aware sharing — shows
· shared N fileswhen other files in the same package import it too (tests, stories and configs excluded) - Package.json cost view — open any
package.jsonto see sizes for its dependencies - Size budgets — set a max KB per import; violations show warnings in the editor and Problems panel
- Lighter alternatives — hover tooltip suggests smaller replacements (moment → dayjs, lodash → lodash-es, etc.)
- Tree-shake hints — suggests named imports when
import *is used on large packages - CLI for CI/CD —
fast-import-cost check src/ --budget 100fails builds when imports are too large - Diff mode —
fast-import-cost diff maincompares import costs between git branches
- Parse — es-module-lexer extracts all import/require statements (<1ms per file)
- Resolve — finds the installed package version via
require.resolve(works with npm, pnpm, yarn with node_modules, bun) - Bundle — esbuild bundles and minifies each import in-process
- Measure — calculates raw, gzip, and brotli sizes
- Cache — results are cached by package name + version, persisted to disk
git clone https://github.com/ruban-s/import-cost.git
cd import-cost
npm install| Command | Description |
|---|---|
npm test |
Run all tests |
npm run build |
Build all packages |
npm run lint |
Lint with Biome |
npm test -w import-cost-core |
Core tests only |
cd packages/vscode-import-cost && npm run typecheck |
Type-check extension |
cd packages/vscode-import-cost && npm run build |
Build + package VSIX |
Changes to the core library are immediately available in the extension via npm workspaces symlink.
See RELEASE.md for the release checklist.
Forked from wix/import-cost. Rewritten in TypeScript with esbuild, es-module-lexer, and Biome — reducing runtime dependencies from 16 to 3.
MIT