mcpField
T
tsdown

tsdown

github.com/oakossDevelopment2186 installsUpdated 12w ago
Repository

About tsdown

tsdown is a library bundler for TypeScript and JavaScript projects, built on Rolldown. It is aimed at library authors who need multiple module formats, declaration files, and package export generation with configured defaults.

Key features

  1. 01Build ESM, CJS, IIFE, and UMD outputs
  2. 02Generate TypeScript declaration files
  3. 03Create package.json exports
  4. 04Watch files and rebuild automatically
  5. 05Run package validation and size reports

Use cases

  1. 01Bundling TypeScript libraries for npm
  2. 02Publishing packages in ESM and CJS formats
  3. 03Building CLI tools with watch mode

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/oakoss/agent-skills --skill tsdown

After installing, type/tsdownin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
advanced-features.md
configuration.md
declaration-files.md

Details

From the project README

tsdown

Overview

tsdown is an elegant library bundler built on Rolldown (Rust-based), providing a complete out-of-the-box solution for building TypeScript and JavaScript libraries. It handles source transformation, multiple output formats (ESM, CJS, IIFE, UMD), TypeScript declaration file generation, and package.json exports field generation with sensible defaults.

When to use: Building TypeScript libraries for npm, generating declaration files, producing dual ESM/CJS packages, bundling CLI tools, library development with watch mode, migrating from tsup.

When NOT to use: Application bundling (use Vite/Rolldown directly), server-side rendering frameworks (use framework bundlers), projects that need Webpack-specific features, simple scripts that need no bundling.

Quick Reference

PatternAPIKey Points
Basic buildnpx tsdownAuto-detects src/index.ts entry
Config filetsdown.config.tsdefineConfig() for type safety
Entry pointsentry: ['src/index.ts']String, array, or object for named entries
Output formatsformat: ['esm', 'cjs']ESM, CJS, IIFE, UMD supported
Declaration filesdts: trueAuto-detects from package.json types field
Fixed extensionsfixedExtension: trueForces .mjs/.cjs and .d.mts/.d.cts
Externalsexternal: ['react']node_modules external by default
Bundle depsnoExternal: ['lodash-es']Force-bundle specific dependencies
Targettarget: 'node18'ES version or Node version
Platformplatform: 'node'node, browser, or neutral
Minificationminify: trueTree shaking enabled separately
Tree shakingtreeshake: trueDead code elimination
Source mapssourcemap: trueInline or external source maps
Watch modetsdown --watchAuto-rebuild on file changes
Clean outputclean: trueRemove output directory before build
Validation--publint --attwPackage quality checks post-build
Size report--reportBundle size with gzip/brotli stats
Multiple configsdefineConfig([...])Array of configs for different outputs
Dynamic configdefineConfig((opts) => {})Function receiving CLI options
Programmatic APIimport { build }Use in Node.js scripts
Banner/Footerbanner: { js: '...' }Prepend/append to output files
onSuccess hookonSuccess: async () => {}Run after successful build
Node protocolnodeProtocol: trueAdd/strip node: prefix on built-in imports

Common Mistakes

MistakeCorrect Pattern
Not setting fixedExtension with dual formatsUse fixedExtension: true for .mjs/.cjs when publishing both ESM and CJS
Bundling all node_modules into library outputDependencies are external by default; use noExternal only for specific deps
Using dts: true without TypeScript configuredEnsure tsconfig.json exists with proper compilerOptions
Setting target too low for modern syntaxMatch target to your minimum supported Node/browser version
Missing types field in package.jsonAdd types or exports types condition for declaration resolution
Not cleaning output before format changesUse clean: true to avoid stale files from previous builds
Inline external for Node built-insNode built-ins (node:fs, etc.) are auto-externalized on platform: 'node'
Using interactive CLI flags in CIUse config file or non-interactive CLI flags for CI builds

Delegation

  • Build configuration review: Use Task agent to analyze tsdown config for correctness
  • Package publishing: Use Explore agent to verify package.json exports and types fields
  • Migration from tsup: Use Task agent to map tsup options to tsdown equivalents

References

Comments

Markdown supported