Files
stack/packages/mosaic/framework/skills/tsdown/references/guide-getting-started.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

2.6 KiB

Getting Started

Quick guide to installing and using tsdown for the first time.

Installation

Install tsdown as a development dependency:

pnpm add -D tsdown

# Optionally install TypeScript if not using isolatedDeclarations
pnpm add -D typescript

Requirements:

  • Node.js 20.19 or higher
  • Experimental support for Deno and Bun

Quick Start Templates

Use create-tsdown CLI for instant setup:

pnpm create tsdown@latest

Provides templates for:

  • Pure TypeScript libraries
  • React component libraries
  • Vue component libraries
  • Ready-to-use configurations

First Bundle

1. Create Source Files

// src/index.ts
import { hello } from './hello.ts';
hello();

// src/hello.ts
export function hello() {
  console.log('Hello tsdown!');
}

2. Create Config File

// tsdown.config.ts
import { defineConfig } from 'tsdown';

export default defineConfig({
  entry: ['./src/index.ts'],
});

3. Run Build

./node_modules/.bin/tsdown

Output: dist/index.mjs

4. Test Output

node dist/index.mjs
# Output: Hello tsdown!

Add to npm Scripts

{
  "scripts": {
    "build": "tsdown"
  }
}

Run with:

pnpm build

CLI Commands

# Check version
tsdown --version

# View help
tsdown --help

# Build with watch mode
tsdown --watch

# Build with specific format
tsdown --format esm,cjs

# Generate type declarations
tsdown --dts

Basic Configurations

TypeScript Library (ESM + CJS)

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm', 'cjs'],
  dts: true,
  clean: true,
});

Browser Library (IIFE)

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['iife'],
  globalName: 'MyLib',
  platform: 'browser',
  minify: true,
});

Multiple Entry Points

export default defineConfig({
  entry: {
    index: 'src/index.ts',
    utils: 'src/utils.ts',
    cli: 'src/cli.ts',
  },
  format: ['esm', 'cjs'],
  dts: true,
});

Using Plugins

Add Rolldown, Rollup, or Unplugin plugins:

import SomePlugin from 'some-plugin';

export default defineConfig({
  entry: ['src/index.ts'],
  plugins: [SomePlugin()],
});

Watch Mode

Enable automatic rebuilds on file changes:

tsdown --watch
# or
tsdown -w

Next Steps