tsup is a super-fast JavaScript/TypeScript bundler built on esbuild. It’s designed for libraries: minimal config, great defaults, and it can spit out ESM + CJS builds (and type declarations) in one go.
Why people use tsup
- 🚀 Speed (esbuild under the hood)
- 🧩 Zero/low config (works from the CLI or a tiny config file)
- 📦 Dual output (esm + cjs) for broad compatibility
- 📝 Type defs: can emit
.d.tswithdts: true - 🔧 Nice extras: watch mode, minify, treeshake, code splitting, sourcemaps
Quick start
npm i -D tsup typescript package.json
{ "scripts": { "build": "tsup", "dev": "tsup --watch", "prepare": "npm run build" } } tsup.config.ts
import { defineConfig } from 'tsup'; export default defineConfig({ entry: ['src/index.ts'], format: ['esm', 'cjs'], dts: true, // emit .d.ts sourcemap: true, clean: true, target: 'es2020', treeshake: true }); tsconfig.json (minimal)
{ "compilerOptions": { "target": "ES2020", "moduleResolution": "bundler", "strict": true, "declaration": true, "emitDeclarationOnly": false, "skipLibCheck": true }, "include": ["src"] } Run:
npm run build You’ll get dist/index.mjs, dist/index.cjs, and dist/index.d.ts.
How it compares
- tsc: compiles TS → JS, but doesn’t bundle (each file out). tsup bundles your code (and can mark deps as external).
- rollup/webpack: very flexible; more config. tsup is “rollup-lite” for libs—fast and simple.
- vite: great for apps/dev servers; you can build libs, but tsup is often simpler for publishing packages.
When to use / not use
- Use tsup for publishing libraries quickly with dual builds + types.
- If you need exotic bundling (custom plugins, unusual module targets), rollup/webpack may still be better.
- If you want no bundling at all, just
tscmight suffice.
Conclusion
That’s it—tsup = fast, simple library bundling with type definitions baked in.
Top comments (0)