bunchee
Zero-config bundler for JS/TS packages — use your package.json as the config.
➜~/project$npm install --save-dev bunchee typescript
➜~/project$
{
"name": "coffee",
"type": "module",
"main": "./dist/index.js",
"scripts": {
"build": "bunchee"
}
}
➜~/project$
Exports File Size
. dist/index.js 5.6 kB
# Why bunchee?
- Zero config - package.json as config
- Auto-generates TypeScript declarations
- Supports ESM, CJS, or dual packages
- Tree-shakeable and monorepo friendly
# Perfect for
- npm packages and component libraries
- Node.js tools, CLI apps, and utilities
- Monorepo workspaces with shared packages
# Learn
## Entry & Convention
Files in src/ folder match export names in package.json:
+--------------------------+---------------------+
| File | Export Name |
+--------------------------+---------------------+
| src/index.ts | "." (default) |
| src/lite.ts | "./lite" |
| src/react/index.ts | "./react" |
+--------------------------+---------------------+
## Directives
Bunchee can manage multiple directives such as "use client", "use server", or "use cache" and automatically split your code into different chunks and preserve the directives properly.
## Wildcard Exports
Use wildcard patterns in exports to dynamically export subpaths:
// package.json
{
"exports": {
"./features/*": "./dist/features/*.js"
}
}
// Output:
// "./features/auth" -> "./dist/features/auth.js"
// "./features/user" -> "./dist/features/user.js"
## Native Addon (.node) Support
supports bundling native Node.js addon files (`.node` binaries).
// src/index.js
import addon from './native-addon.node'
// The .node file is copied to dist/ and
// the import is rewritten to load it at runtime
- Up to 5.3× faster on a 57-entry build with declarations
- New package lint checks catch publishing mistakes
- ESM-first package preparation with standard exports
Migrating from bunchee 6
- Use Node.js 22.12 or newer.
- Expect ES2022 output by default; set
--target when an older target is required. - Import bunchee's Node.js API with ESM
import instead of require(). bunchee prepare now generates ESM-only packages; pass --cjs for dual ESM and CommonJS output.- Replace the removed
--prepare build flag with the bunchee prepare command. - TypeScript 7 projects need
@typescript/typescript6 for declaration generation.
Complete migration guide · Plain-text docs for agents