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.
2.0 KiB
2.0 KiB
name, description
| name | description |
|---|---|
| library-development | Building and publishing TypeScript libraries with tsdown. Use when creating npm packages, configuring library bundling, or setting up package.json exports. |
Library Development
| 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.