tsdown
tsdown TypeScript bundler built on Rolldown for libraries and packages. Use when bundling TypeScript libraries, generating declaration files, or publishing npm packages. Use for tsdown, bundler, rolldown, dts, declaration, library-build, esm, cjs, treeshake.
What this skill does
# 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
| Pattern | API | Key Points |
| ----------------- | ---------------------------- | -------------------------------------------- |
| Basic build | `npx tsdown` | Auto-detects `src/index.ts` entry |
| Config file | `tsdown.config.ts` | `defineConfig()` for type safety |
| Entry points | `entry: ['src/index.ts']` | String, array, or object for named entries |
| Output formats | `format: ['esm', 'cjs']` | ESM, CJS, IIFE, UMD supported |
| Declaration files | `dts: true` | Auto-detects from package.json `types` field |
| Fixed extensions | `fixedExtension: true` | Forces `.mjs`/`.cjs` and `.d.mts`/`.d.cts` |
| Externals | `external: ['react']` | node_modules external by default |
| Bundle deps | `noExternal: ['lodash-es']` | Force-bundle specific dependencies |
| Target | `target: 'node18'` | ES version or Node version |
| Platform | `platform: 'node'` | `node`, `browser`, or `neutral` |
| Minification | `minify: true` | Tree shaking enabled separately |
| Tree shaking | `treeshake: true` | Dead code elimination |
| Source maps | `sourcemap: true` | Inline or external source maps |
| Watch mode | `tsdown --watch` | Auto-rebuild on file changes |
| Clean output | `clean: true` | Remove output directory before build |
| Validation | `--publint --attw` | Package quality checks post-build |
| Size report | `--report` | Bundle size with gzip/brotli stats |
| Multiple configs | `defineConfig([...])` | Array of configs for different outputs |
| Dynamic config | `defineConfig((opts) => {})` | Function receiving CLI options |
| Programmatic API | `import { build }` | Use in Node.js scripts |
| Banner/Footer | `banner: { js: '...' }` | Prepend/append to output files |
| onSuccess hook | `onSuccess: async () => {}` | Run after successful build |
| Node protocol | `nodeProtocol: true` | Add/strip `node:` prefix on built-in imports |
## Common Mistakes
| Mistake | Correct Pattern |
| ----------------------------------------------- | ----------------------------------------------------------------------------- |
| Not setting `fixedExtension` with dual formats | Use `fixedExtension: true` for `.mjs`/`.cjs` when publishing both ESM and CJS |
| Bundling all node_modules into library output | Dependencies are external by default; use `noExternal` only for specific deps |
| Using `dts: true` without TypeScript configured | Ensure `tsconfig.json` exists with proper `compilerOptions` |
| Setting `target` too low for modern syntax | Match target to your minimum supported Node/browser version |
| Missing `types` field in package.json | Add `types` or `exports` types condition for declaration resolution |
| Not cleaning output before format changes | Use `clean: true` to avoid stale files from previous builds |
| Inline `external` for Node built-ins | Node built-ins (`node:fs`, etc.) are auto-externalized on `platform: 'node'` |
| Using interactive CLI flags in CI | Use 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
- [Configuration: config file, entry points, output formats, target, platform, externals](references/configuration.md)
- [Declaration files: DTS generation, isolated declarations, type bundling](references/declaration-files.md)
- [Advanced features: plugins, code splitting, tree shaking, watch mode, validation](references/advanced-features.md)
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.