Skip to content

gentleeduck/duck-ui / .claude/skills/tsdown

tsdown

Verified

Bundle TypeScript and JavaScript libraries with blazing-fast speed powered by Rolldown. Use when building libraries, generating type declarations, bundling for multiple formats, or migrating from tsup.

FileKindSize
LICENSE.mdmarkdown1.1 KB
README.mdmarkdown2.2 KB
SKILL.mdskill md12.6 KB
SYNC.mdmarkdown140 B
agents/openai.yamlconfig98 B
references/README.mdmarkdown4.7 KB
references/advanced-benchmark.mdmarkdown265 B
references/advanced-ci.mdmarkdown2.0 KB
references/advanced-hooks.mdmarkdown6.9 KB
references/advanced-plugins.mdmarkdown6.6 KB
references/advanced-programmatic.mdmarkdown5.9 KB
references/advanced-rolldown-options.mdmarkdown2.3 KB
references/guide-getting-started.mdmarkdown3.1 KB
references/guide-introduction.mdmarkdown1.6 KB
references/guide-migrate-from-tsup.mdmarkdown4.8 KB
references/option-cjs-default.mdmarkdown1.9 KB
references/option-cleaning.mdmarkdown4.8 KB
references/option-config-file.mdmarkdown5.5 KB
references/option-css.mdmarkdown6.9 KB
references/option-dependencies.mdmarkdown7.4 KB
references/option-dts.mdmarkdown4.5 KB
references/option-entry.mdmarkdown3.6 KB
references/option-exe.mdmarkdown3.3 KB
references/option-lint.mdmarkdown2.9 KB
references/option-log-level.mdmarkdown1.8 KB
references/option-minification.mdmarkdown3.5 KB
references/option-output-directory.mdmarkdown4.6 KB
references/option-output-format.mdmarkdown3.6 KB
references/option-package-exports.mdmarkdown5.4 KB
references/option-platform.mdmarkdown5.1 KB
references/option-root.mdmarkdown1.8 KB
references/option-shims.mdmarkdown5.5 KB
references/option-sourcemap.mdmarkdown5.4 KB
references/option-target.mdmarkdown4.0 KB
references/option-tree-shaking.mdmarkdown5.1 KB
references/option-unbundle.mdmarkdown5.5 KB
references/option-watch-mode.mdmarkdown4.6 KB
references/recipe-react.mdmarkdown5.9 KB
references/recipe-solid.mdmarkdown783 B
references/recipe-svelte.mdmarkdown1.4 KB
references/recipe-vue.mdmarkdown6.4 KB
references/recipe-wasm.mdmarkdown2.5 KB
references/reference-cli.mdmarkdown7.3 KB

references/option-target.md

View on GitHub
# Target Environment

Configure JavaScript syntax transformations for target environments.

## Overview

The `target` option controls which JavaScript features are downleveled (transformed to older syntax) for compatibility.

**Important:** Only affects syntax transformations, not runtime polyfills.

## Default Behavior

tsdown auto-reads from `package.json`:

```json
// package.json
{
  "engines": {
    "node": ">=18.0.0"
  }
}
```

Automatically sets `target` to `node18.0.0`.

If no `engines.node` field exists, behaves as if `target: false` (no transformations).

## Disabling Transformations

Set to `false` to preserve modern syntax:

```ts
export default defineConfig({
  target: false,
})
```

**Result:**
- No JavaScript downleveling
- Modern features preserved (optional chaining `?.`, nullish coalescing `??`, etc.)

**Use when:**
- Targeting modern environments
- Handling transformations elsewhere
- Building libraries for further processing

## Setting Target

### CLI

```bash
# Single target
tsdown --target es2020
tsdown --target node20

# Multiple targets
tsdown --target chrome100 --target node20.18

# Disable
tsdown --no-target
```

### Config File

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

### Multiple Targets

```ts
export default defineConfig({
  entry: ['src/index.ts'],
  target: ['chrome100', 'safari15', 'node18'],
})
```

## Supported Targets

### ECMAScript Versions

- `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020`, `es2021`, `es2022`, `es2023`, `esnext`

### Browser Versions

- `chrome100`, `safari18`, `firefox110`, `edge100`, etc.

### Node.js Versions

- `node16`, `node18`, `node20`, `node20.18`, etc.

## Examples

### Modern Browsers

```ts
export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm'],
  target: ['chrome100', 'safari15', 'firefox100'],
})
```

### Node.js Library

```ts
export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm', 'cjs'],
  target: 'node18',
})
```

### Legacy Support

```ts
export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm'],
  target: 'es2015',  // Maximum compatibility
})
```

### Per-Format Targets

```ts
export default defineConfig({
  entry: ['src/index.ts'],
  format: {
    esm: {
      target: 'es2020',
    },
    cjs: {
      target: 'node16',
    },
  },
})
```

## Decorators

### Legacy Decorators (Stage 2)

Enable in `tsconfig.json`:

```json
{
  "compilerOptions": {
    "experimentalDecorators": true
  }
}
```

### Stage 3 Decorators

**Not currently supported** by tsdown/Rolldown/Oxc.

See [oxc issue #9170](https://github.com/oxc-project/oxc/issues/9170).

## Common Patterns

### Universal Library

```ts
export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm', 'cjs'],
  target: 'es2020',  // Wide compatibility
})
```

### Modern-Only Library

```ts
export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm'],
  target: false,  // No transformations
})
```

### Browser Component

```ts
export default defineConfig({
  entry: ['src/index.tsx'],
  format: ['esm'],
  target: ['chrome100', 'safari15', 'firefox100'],
  platform: 'browser',
})
```

## CSS Targeting

When `@tsdown/css` is installed and a browser target is set, CSS syntax is also lowered automatically:

```ts
export default defineConfig({
  target: 'chrome108',  // CSS nesting will be flattened
})
```

See [CSS](option-css.md) for full CSS configuration options.

## Tips

1. **Let tsdown auto-detect** from package.json when possible
2. **Use `false`** for modern-only builds
3. **Specify multiple targets** for broader compatibility
4. **Use legacy decorators** with `experimentalDecorators`
5. **Install `@tsdown/css`** for CSS support and syntax lowering
6. **Test output** in target environments

## Related Options

- [Platform](option-platform.md) - Runtime environment
- [Output Format](option-output-format.md) - Module formats
- [Minification](option-minification.md) - Code optimization
- [CSS](option-css.md) - CSS handling and preprocessors
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall