All skills

Use when bundling TypeScript libraries - provides tsdown configuration, dual ESM/CJS output, .d.ts generation, and plugin authoring

  • 5 files
  • 15.4 KB
  • MIT
  • Updated 8 months ago
  • GitHub

Use this Skill: https://skilld.dev/gh/onmax/claude-config/tsdown

This session only. Nothing lands on disk.

referencesfeatures.md

≈844 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Features

Tree Shaking

Enabled by default - removes unused code.

defineConfig({
  treeshake: true,   // Default
  treeshake: false,  // Disable
})

Minification

defineConfig({
  minify: true,
})

Uses Oxc (fast, currently alpha).

Source Maps

defineConfig({
  sourcemap: true,
})

Auto-enabled if declarationMap: true in tsconfig.json.

Shims

CJS in ESM

__dirname and __filename not available in ESM:

defineConfig({
  shims: true,  // Provides __dirname, __filename
})

require in ESM

Auto-injected when platform: 'node':

// Generated:
const require = createRequire(import.meta.url)

ESM in CJS

Always enabled - import.meta.url, import.meta.dirname, import.meta.filename work in CJS.

CJS Default Export

When CJS output has only default export:

// Source
export default function greet() {}

// CJS Output
module.exports = greet

// Declaration
declare function greet(): void
export = greet

Unbundle Mode

Transpile-only - preserves file structure:

defineConfig({
  entry: ['src/index.ts'],
  unbundle: true,
})

Input:

src/
  index.ts
  mod.ts

Output:

dist/
  index.js
  mod.js

Watch Mode

defineConfig({
  watch: true,
  // Or specific paths
  watch: ['./src', './lib'],
})
tsdown --watch
tsdown --watch ./src
tsdown --ignore-watch node_modules

Post-Build Command

tsdown --watch --on-success "node dist/index.mjs"

Copy Assets

tsdown --copy public

Environment Variables

tsdown --env.NODE_ENV=production
tsdown --env-file .env.production
tsdown --env-prefix APP_

Node Protocol

Control Node.js built-in imports:

defineConfig({
  nodeProtocol: true,     // fs → node:fs
  nodeProtocol: 'strip',  // node:fs → fs
  nodeProtocol: false,    // Keep as-is (default)
})

CSS

defineConfig({
  css: {
    splitting: false,      // Single CSS file
    fileName: 'styles.css',
  },
})

CSS targeting (requires unplugin-lightningcss):

pnpm add -D unplugin-lightningcss

JSX

Built-in support via Rolldown:

defineConfig({
  inputOptions: {
    transform: {
      jsx: 'react',  // Classic transform
    },
  },
})

Framework Support

React

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

export default defineConfig({
  entry: ['./src/index.ts'],
  platform: 'neutral',
  dts: true,
})

React Compiler:

pnpm add -D @rollup/plugin-babel babel-plugin-react-compiler
import pluginBabel from '@rollup/plugin-babel'

defineConfig({
  plugins: [
    pluginBabel({
      babelHelpers: 'bundled',
      parserOpts: {
        sourceType: 'module',
        plugins: ['jsx', 'typescript'],
      },
      plugins: ['babel-plugin-react-compiler'],
      extensions: ['.js', '.jsx', '.ts', '.tsx'],
    }),
  ],
})

Vue

pnpm add -D unplugin-vue vue-tsc
import { defineConfig } from 'tsdown'
import Vue from 'unplugin-vue/rolldown'

export default defineConfig({
  entry: ['./src/index.ts'],
  platform: 'neutral',
  plugins: [Vue({ isProduction: true })],
  dts: { vue: true },
})

Quick Start Templates

npx create-tsdown@latest -t vue
npx create-tsdown@latest -t react
npx create-tsdown@latest -t react-compiler

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at 6a37106. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 10 hours ago.

Activeupdated 8 months ago

README badge

README badge for onmax/claude-config/tsdown