Introduction
What Packem is, how it works, and when to use it
Introduction
Packem is a bundler for Node.js and TypeScript libraries. It reads your package.json exports, picks the right entry points, and produces optimized ESM, CJS, or IIFE bundles — with TypeScript declarations, CSS processing, and tree shaking included.
Under the hood it uses Rollup for bundling and lets you swap in the compiler that fits your project: esbuild, swc, OXC, sucrase, or the official TypeScript compiler.
How Packem differs from plain Rollup
Rollup is a powerful general-purpose bundler, but shipping a library still requires wiring up dozens of plugins and options. Packem handles that for you:
- Package.json driven — Entry points, output formats, and declaration paths are read directly from your
package.jsonexports. No duplicate configuration. - Built-in TypeScript declarations — Generate
.d.tsfiles automatically, including isolated declarations. - Multiple transformers — Switch compilers with a single config change instead of swapping plugin chains.
- CSS pipeline included — Sass, Less, Stylus, PostCSS, and CSS Modules work without extra setup.
- Multi-runtime exports — Target Node.js, browser, edge-light, and react-server from one build.
What it bundles
Packem handles everything a modern library needs:
- TypeScript and JavaScript —
.ts,.tsx,.js, and.jsxfiles with modern syntax support. - Type declarations —
.d.tsgeneration with isolated declaration support. - Multiple output formats — ESM, CJS, and IIFE in a single build.
- CSS and preprocessors — CSS, Sass, Less, Stylus, PostCSS, and CSS Modules.
- React components — Server Components, Client Components, and server actions.
- Assets — JSON, WASM, text files, and Node.js native addons.
- Dynamic imports — Code splitting with shared modules across entry points.
Tree shaking, minification, source maps, and bundle analysis are built in.
Choosing a transformer
Each transformer makes a different trade-off between speed and feature coverage:
| Transformer | Speed | TypeScript | JSX | Decorators |
|---|---|---|---|---|
| esbuild | Fastest | Yes | Yes | No |
| swc | Very fast | Yes | Yes | Yes |
| OXC | Very fast | Yes | Yes | Partial |
| sucrase | Fast | Yes | Yes | No |
| TypeScript | Moderate | Full type checking | Yes | Yes |
Most projects should start with esbuild. Switch to swc if you need decorator support, or to TypeScript if you need full type checking during the build. See Transformers for configuration details.
Package.json as the source of truth
Packem reads your package.json to determine:
- Entry points from
exports,main,module, andbinfields - Output formats (ESM/CJS) from export conditions
- Declaration output from the
typesfield - Build targets and compatibility requirements
This keeps your build configuration and your package's public API in sync.
Credits
Packem builds on the work of the open-source community. In particular:
- Rollup — The bundling engine and plugin system that powers Packem.
- esbuild — Demonstrated what fast native compilation looks like.
- tsup — Inspired the out-of-the-box developer experience and many CLI options.
- unbuild — Inspired the hooks system and configuration patterns.
- swc and OXC — Pushing the limits of JavaScript compilation performance.
Next steps
- Getting Started — Install Packem and create your first bundle.
- Configuration — Customize your build for production.
- Examples — Copy-and-paste starters for common setups.