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.json exports. No duplicate configuration.
  • Built-in TypeScript declarations — Generate .d.ts files 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 .jsx files with modern syntax support.
  • Type declarations.d.ts generation 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:

TransformerSpeedTypeScriptJSXDecorators
esbuildFastestYesYesNo
swcVery fastYesYesYes
OXCVery fastYesYesPartial
sucraseFastYesYesNo
TypeScriptModerateFull type checkingYesYes

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, and bin fields
  • Output formats (ESM/CJS) from export conditions
  • Declaration output from the types field
  • 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

Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues