Files
gt-agent-company/.agents/skills/antfu/references/library-development.md
sexygoat 3c62cc1cd1 first
2026-03-31 18:41:52 +08:00

1.8 KiB

name, description
name description
library-development Anthony Fu's preferences for building and publishing JavaScript/TypeScript libraries

Library Development Preferences

Preferences for bundling and publishing TypeScript libraries.

Key Decisions

Aspect Choice
Bundler tsdown
Output Pure ESM only (no CJS)
DTS Generated via tsdown
Exports Auto-generated via tsdown

tsdown Configuration

Use tsdown with these options enabled:

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

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm'],
  dts: true,
  exports: true,
})
Option Value Purpose
format ['esm'] Pure ESM, no CommonJS
dts true Generate .d.ts files
exports true Auto-update exports field in package.json

Multiple Entry Points

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

The exports: true option auto-generates the exports field in package.json when running tsdown.


package.json

Required fields for pure ESM library:

{
  "type": "module",
  "main": "./dist/index.mjs",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.mts",
  "files": ["dist"],
  "scripts": {
    "build": "tsdown",
    "prepack": "pnpm build",
    "test": "vitest",
    "release": "bumpp -r"
  }
}

The exports field is managed by tsdown when exports: true.

prepack Script

For each public package, add "prepack": "pnpm build" to scripts. This ensures the package is automatically built before publishing (e.g., when running npm publish or pnpm publish). This prevents accidentally publishing stale or missing build artifacts.