The Elegant Bundler for Libraries built on Rolldown with TypeScript support, comprehensive plugin ecosystem, and zero-configuration setup
—
Command-line interface with comprehensive options for building, watching, and managing projects. The CLI provides extensive configuration options, debug capabilities, and migration utilities for seamless development workflows.
Main CLI execution function that handles command parsing and execution.
/**
* Run the tsdown CLI with command-line arguments
*/
function runCLI(): Promise<void>;Basic Usage:
# Build with defaults
npx tsdown
# Build specific files
npx tsdown src/index.ts src/cli.ts
# Build with options
npx tsdown --format esm,cjs --dts --sourcemap
# Watch mode
npx tsdown --watch
# Debug mode
npx tsdown --debugMain build command with extensive configuration options.
tsdown [files...] [options]# Entry files
tsdown src/index.ts src/cli.ts
# Configuration
-c, --config <filename> # Use custom config file
--no-config # Disable config file
# External dependencies
--external <module> # Mark dependencies as external
# Source processing
--tsconfig <tsconfig> # Set tsconfig path
--from-vite [vitest] # Reuse config from Vite or Vitest# Format and output
-f, --format <format> # Bundle format: esm, cjs, iife, umd (default: esm)
-d, --out-dir <dir> # Output directory (default: dist)
# Code generation
--dts # Generate TypeScript declaration files
--sourcemap # Generate source maps (default: false)
--minify # Minify output code
# Build behavior
--clean # Clean output directory
--no-clean # Disable cleaning output directory
--unbundle # Unbundle mode (mirror input structure)# Build target and platform
--target <target> # Bundle target (e.g., es2015, esnext, node18)
--platform <platform> # Target platform: node, neutral, browser (default: node)
# Tree-shaking and optimization
--treeshake # Enable tree-shaking (default: true)
--shims # Enable CJS and ESM shims (default: false)
# Environment
--env.* <value> # Define compile-time env variables
--on-success <command> # Command to run on success# Watch mode
-w, --watch [path] # Enable watch mode
--ignore-watch <path> # Ignore custom paths in watch mode
# Debugging
--debug [feat] # Show debug logs (tsdown:* or specific features)# Linting and validation
--publint # Enable publint (default: false)
--attw # Enable Are The Types Wrong (default: false)
--unused # Enable unused dependencies check (default: false)
# Reporting
--report # Enable size report (default: true)# Workspace and filtering
-W, --workspace [dir] # Enable workspace mode
-F, --filter <pattern> # Filter workspace packages (regex or substring)# Experimental features
--exports # Generate export metadata for package.json
--copy <dir> # Copy files to output directory
--public-dir <dir> # Alias for --copy (deprecated)
# Logging
-l, --logLevel <level> # Set log level: info, warn, error, silent
--fail-on-warn # Fail on warnings (default: true)Complete Example:
tsdown src/index.ts \
--format esm,cjs \
--target node18 \
--dts \
--sourcemap \
--clean \
--minify \
--external react,react-dom \
--env.NODE_ENV=production \
--publint \
--attw \
--watchMigration utility for converting tsup configurations to tsdown.
tsdown migrate [options]/**
* Migrate from tsup to tsdown configuration
* @param options - Migration options
*/
function migrate(options: {
cwd?: string;
dryRun?: boolean;
}): Promise<void>;Migration Options:
-c, --cwd <dir> # Working directory (default: current directory)
-d, --dry-run # Preview changes without applying themUsage Examples:
# Preview migration changes
tsdown migrate --dry-run
# Apply migration in current directory
tsdown migrate
# Migrate project in specific directory
tsdown migrate --cwd ./packages/my-libMigration Process:
package.json Updates:
tsup dependency to tsdowntsup commands in scripts with tsdowntsup configuration field to tsdownConfiguration File Migration:
tsup.config.* files to tsdown.config.*Supported File Extensions:
.ts, .cts, .mts.js, .cjs, .mjs.jsonComprehensive debugging system with namespaced debug output.
# Enable all debug output
tsdown --debug
# Enable specific debug namespaces
tsdown --debug options,external
# Debug specific features
tsdown --debug rolldown,pluginsAvailable Debug Namespaces:
tsdown:options - Options resolution and validationtsdown:external - External dependency handlingtsdown:report - Size reporting and analysistsdown:rolldown - Rolldown integrationtsdown:plugins - Plugin system operationstsdown:workspace - Workspace discovery and processingEnvironment variables that affect CLI behavior.
# Debug output
DEBUG=tsdown:* # Enable all debug output
DEBUG=tsdown:options,external # Enable specific namespaces
# Node.js optimizations
NODE_OPTIONS=--enable-source-maps # Enable source map supportThe CLI uses standard exit codes for process management:
0 - Success1 - Build failure, configuration error, or user cancellationThe CLI provides structured, colorized output with progress indicators:
tsdown v0.14.2 powered by rolldown v0.x.x
✓ my-package Build complete in 1234ms
dist/index.mjs 2.1 kB │ gzip: 1.1 kB
dist/index.d.mts 856 B │ gzip: 445 B
2 files, total: 2.9 kBThe CLI automatically discovers configuration files in the following order:
--config flagtsdown.config.tstsdown.config.ctstsdown.config.mtstsdown.config.jstsdown.config.cjstsdown.config.mjstsdown.config.jsonnpm scripts integration:
{
"scripts": {
"build": "tsdown",
"build:watch": "tsdown --watch",
"build:prod": "tsdown --minify --clean",
"dev": "tsdown --watch --sourcemap",
"check": "tsdown --publint --attw --unused"
}
}CI/CD integration:
# GitHub Actions example
- name: Build library
run: |
npm run build
npm run check
# With specific options for CI
- name: Build and validate
run: tsdown --format esm,cjs --dts --publint --attw --fail-on-warnInstall with Tessl CLI
npx tessl i tessl/npm-tsdown