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.

referencesoutput.md

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

Output Options

Format

Default: esm

defineConfig({
  format: 'esm',                 // ECMAScript Modules
  format: 'cjs',                 // CommonJS
  format: 'iife',                // Browser script
  format: 'umd',                 // Universal
  format: ['esm', 'cjs'],        // Multiple
})

Format-specific config:

defineConfig({
  format: {
    esm: { target: ['es2015'] },
    cjs: { target: ['node20'] },
  },
})

Output Directory

defineConfig({
  outDir: 'dist',  // Default
})
tsdown -d ./build
tsdown --out-dir ./build

Target

Syntax downleveling (no polyfills):

defineConfig({
  target: 'es2020',
  target: 'node20',
  target: ['chrome100', 'firefox90'],
})

Default: reads from engines.node in package.json.

Disable transformations:

defineConfig({
  target: false,  // Preserve modern syntax
})

Platform

defineConfig({
  platform: 'node',     // Default, Node.js built-ins external
  platform: 'browser',  // Web browsers
  platform: 'neutral',  // Platform-agnostic
})

Module resolution:

  • node: mainFields: ['main', 'module']
  • browser: mainFields: ['browser', 'module', 'main']
  • neutral: relies on exports field only

Declaration Files (.d.ts)

defineConfig({
  dts: true,  // Enable
})

Auto-enabled if types or typings in package.json.

Performance with isolatedDeclarations

For fastest .d.ts generation:

// tsconfig.json
{
  "compilerOptions": {
    "isolatedDeclarations": true
  }
}

Uses oxc-transform instead of slower TypeScript.

Declaration Maps

defineConfig({
  dts: {
    sourcemap: true,  // .d.ts.map files
  },
})

Or via tsconfig.json:

{
  "compilerOptions": {
    "declarationMap": true
  }
}

Vue Support

defineConfig({
  dts: { vue: true },  // Requires vue-tsc
})

Dependencies

Default Behavior

Type Bundled?
dependencies No (external)
peerDependencies No (external)
devDependencies Yes (if imported)
Phantom deps Yes (if imported)

Skip All node_modules

defineConfig({
  skipNodeModulesBundle: true,
})

Custom External

defineConfig({
  external: ['lodash', /^@my-scope\//],
})

Force Bundle

defineConfig({
  noExternal: ['some-package'],  // Bundle despite being in deps
})

Package Exports

Auto-generate exports, main, module, types:

defineConfig({
  exports: true,
})

Export All Files

defineConfig({
  exports: {
    all: true,  // Not just entry files
  },
})

Dev Exports

Point to source during development:

defineConfig({
  exports: {
    devExports: true,
  },
})

exports → source, publishConfig.exports → built.

CSS Exports

defineConfig({
  css: {
    splitting: false,
    fileName: 'my-library.css',
  },
  exports: true,
})

Custom Exports

defineConfig({
  exports: {
    customExports(pkg, context) {
      pkg['./foo'] = './foo.js'
      return pkg
    },
  },
})

Cleaning

Output directory cleaned by default:

defineConfig({
  clean: true,   // Default
  clean: false,  // Keep existing
})

Example package.json

{
  "name": "my-lib",
  "type": "module",
  "main": "./dist/index.cjs",
  "module": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "import": {
        "types": "./dist/index.d.ts",
        "default": "./dist/index.js"
      },
      "require": {
        "types": "./dist/index.d.cts",
        "default": "./dist/index.cjs"
      }
    }
  },
  "files": ["dist"]
}

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 12 hours ago.

Activeupdated 8 months ago

README badge

README badge for onmax/claude-config/tsdown