Calculate the bundle size of imported packages in JavaScript and TypeScript with a CLI and Node.js API. Version 5.5.0, actively maintained (2025 release). Powered by esbuild and es-module-lexer for high performance — scans 50+ files in less than a second. Provides minified, gzipped, and brotli sizes; identifies tree-shakeable packages; supports budget enforcement, JSON output, ignore patterns, watch mode, and git diff for CI/CD. Works with npm, pnpm, yarn, and bun. Aims to be a drop-in replacement for the deprecated import-cost VS Code extension backend, offering more accuracy and speed than webpack-bundle-analyzer or cost-of-modules.
npm install import-cost-coreNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates API usage: scanning a TypeScript file for imports and logging size metrics with cleanup.
Call `emitter.removeAllListeners()` before creating a new emitter for the same file.
Use `import type { PackageInfo } from 'import-cost-core'` to import only the type, or use `import { PackageInfo } from 'import-cost-core'` only if you need the runtime value (it does not exist).Replace `import importCost from 'import-cost-core'` with `import { importCost } from 'import-cost-core'`.Update to v3.0+ which restored the optional config parameter or adjust your calls to include the language parameter.
Call `cleanup()` when done, e.g., after the 'done' event or in a process 'exit' handler.
Use `import type { PackageInfo } from 'import-cost-core'` instead.Run `npm install import-cost-core` in your project.
Use `import { importCost } from 'import-cost-core'`.Run `npm install esbuild` alongside import-cost-core.