T
teaganga
Guest
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.
package.json
tsup.config.ts
tsconfig.json (minimal)
Run:
Youβll get
Thatβs itβtsup = fast, simple library bundling with type definitions baked in.
Continue reading...
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.ts
withdts: true
Nice extras: watch mode, minify, treeshake, code splitting, sourcemaps
Quick start
Code:
npm i -D tsup typescript
package.json
Code:
{
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"prepare": "npm run build"
}
}
tsup.config.ts
Code:
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)
Code:
{
"compilerOptions": {
"target": "ES2020",
"moduleResolution": "bundler",
"strict": true,
"declaration": true,
"emitDeclarationOnly": false,
"skipLibCheck": true
},
"include": ["src"]
}
Run:
Code:
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
tsc
might suffice.
Conclusion
Thatβs itβtsup = fast, simple library bundling with type definitions baked in.
Continue reading...