A CLI tool and Node.js library for calculating the bundle size of imported packages in JavaScript and TypeScript files. v5.5.0, actively maintained. Powered by esbuild and es-module-lexer, it offers fast scanning (50+ files in under 1 second) and provides minified, gzipped, and brotli sizes. Differentiators include tree-shaking awareness, a `--budget` flag for CI enforcement, diff support between git branches, and zero-config operation with npm, pnpm, yarn, and bun. Ships TypeScript definitions.
npm install fast-import-costNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates the library API: importCost emitter with start, calculated, done, and error events, plus cleanup.
Call cleanup() after the emitter emits 'done' or when shutting down your application.
Use path.resolve() to get an absolute path before passing to importCost.
Check packages.length in the 'start' event handler before proceeding.
Use import statements instead of require(); configure tsconfig.json appropriately.
Ensure --budget value is realistic for individual packages, or use --json to custom parse results.
Install the package: npm install fast-import-cost. Then use import { ... } from 'fast-import-cost' instead of require().Ensure you import cleanup: import { cleanup } from 'fast-import-cost'; then call cleanup() after emitter is done.Use path.resolve(__dirname, 'file.ts') to get absolute path before passing to importCost.
Call emitter.removeAllListeners() on old emitters before creating new ones, or increase max listeners if appropriate.