format: apply repo prettier (3.8.1) to the folded skills tree
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.
This commit is contained in:
@@ -11,19 +11,19 @@ tsdown can be imported and used programmatically in your Node.js scripts, custom
|
||||
### Simple Build
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
dts: true,
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
### With Options
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
@@ -33,7 +33,7 @@ await build({
|
||||
minify: true,
|
||||
sourcemap: true,
|
||||
clean: true,
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
## API Reference
|
||||
@@ -43,18 +43,21 @@ await build({
|
||||
Main function to run a build.
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
await build(options)
|
||||
await build(options);
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `options` - Build configuration object (same as config file)
|
||||
|
||||
**Returns:**
|
||||
|
||||
- `Promise<void>` - Resolves when build completes
|
||||
|
||||
**Throws:**
|
||||
|
||||
- Build errors if compilation fails
|
||||
|
||||
## Configuration Object
|
||||
@@ -62,7 +65,7 @@ await build(options)
|
||||
All config file options are available:
|
||||
|
||||
```ts
|
||||
import { build, defineConfig } from 'tsdown'
|
||||
import { build, defineConfig } from 'tsdown';
|
||||
|
||||
const config = defineConfig({
|
||||
entry: ['src/index.ts'],
|
||||
@@ -71,15 +74,17 @@ const config = defineConfig({
|
||||
minify: true,
|
||||
sourcemap: true,
|
||||
external: ['react', 'react-dom'],
|
||||
plugins: [/* plugins */],
|
||||
plugins: [
|
||||
/* plugins */
|
||||
],
|
||||
hooks: {
|
||||
'build:done': async () => {
|
||||
console.log('Build complete!')
|
||||
console.log('Build complete!');
|
||||
},
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
await build(config)
|
||||
await build(config);
|
||||
```
|
||||
|
||||
See [Config Reference](option-config-file.md) for all options.
|
||||
@@ -90,25 +95,26 @@ See [Config Reference](option-config-file.md) for all options.
|
||||
|
||||
```ts
|
||||
// scripts/build.ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
async function main() {
|
||||
console.log('Building library...')
|
||||
console.log('Building library...');
|
||||
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
dts: true,
|
||||
clean: true,
|
||||
})
|
||||
});
|
||||
|
||||
console.log('Build complete!')
|
||||
console.log('Build complete!');
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
main().catch(console.error);
|
||||
```
|
||||
|
||||
Run with:
|
||||
|
||||
```bash
|
||||
tsx scripts/build.ts
|
||||
```
|
||||
@@ -116,7 +122,7 @@ tsx scripts/build.ts
|
||||
### Multiple Builds
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
// Build main library
|
||||
await build({
|
||||
@@ -124,7 +130,7 @@ await build({
|
||||
format: ['esm', 'cjs'],
|
||||
outDir: 'dist',
|
||||
dts: true,
|
||||
})
|
||||
});
|
||||
|
||||
// Build CLI tool
|
||||
await build({
|
||||
@@ -133,15 +139,15 @@ await build({
|
||||
outDir: 'dist/bin',
|
||||
platform: 'node',
|
||||
shims: true,
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
### Conditional Build
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
@@ -149,64 +155,64 @@ await build({
|
||||
minify: !isDev,
|
||||
sourcemap: isDev,
|
||||
clean: !isDev,
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
### With Error Handling
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
try {
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
dts: true,
|
||||
})
|
||||
console.log('✅ Build successful')
|
||||
});
|
||||
console.log('✅ Build successful');
|
||||
} catch (error) {
|
||||
console.error('❌ Build failed:', error)
|
||||
process.exit(1)
|
||||
console.error('❌ Build failed:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
```
|
||||
|
||||
### Automated Workflow
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { execSync } from 'child_process'
|
||||
import { build } from 'tsdown';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
async function release() {
|
||||
// Clean
|
||||
console.log('Cleaning...')
|
||||
execSync('rm -rf dist')
|
||||
console.log('Cleaning...');
|
||||
execSync('rm -rf dist');
|
||||
|
||||
// Build
|
||||
console.log('Building...')
|
||||
console.log('Building...');
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
dts: true,
|
||||
minify: true,
|
||||
})
|
||||
});
|
||||
|
||||
// Test
|
||||
console.log('Testing...')
|
||||
execSync('npm test')
|
||||
console.log('Testing...');
|
||||
execSync('npm test');
|
||||
|
||||
// Publish
|
||||
console.log('Publishing...')
|
||||
execSync('npm publish')
|
||||
console.log('Publishing...');
|
||||
execSync('npm publish');
|
||||
}
|
||||
|
||||
release().catch(console.error)
|
||||
release().catch(console.error);
|
||||
```
|
||||
|
||||
### Build with Post-Processing
|
||||
|
||||
```ts
|
||||
import { build } from 'tsdown'
|
||||
import { copyFileSync } from 'fs'
|
||||
import { build } from 'tsdown';
|
||||
import { copyFileSync } from 'fs';
|
||||
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
@@ -215,12 +221,12 @@ await build({
|
||||
hooks: {
|
||||
'build:done': async () => {
|
||||
// Copy additional files
|
||||
copyFileSync('README.md', 'dist/README.md')
|
||||
copyFileSync('LICENSE', 'dist/LICENSE')
|
||||
console.log('Copied additional files')
|
||||
copyFileSync('README.md', 'dist/README.md');
|
||||
copyFileSync('LICENSE', 'dist/LICENSE');
|
||||
console.log('Copied additional files');
|
||||
},
|
||||
},
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
## Watch Mode
|
||||
@@ -229,12 +235,12 @@ Unfortunately, watch mode is not directly exposed in the programmatic API. Use t
|
||||
|
||||
```ts
|
||||
// Use CLI for watch mode
|
||||
import { spawn } from 'child_process'
|
||||
import { spawn } from 'child_process';
|
||||
|
||||
spawn('tsdown', ['--watch'], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
## Integration Examples
|
||||
@@ -243,30 +249,30 @@ spawn('tsdown', ['--watch'], {
|
||||
|
||||
```ts
|
||||
// gulpfile.js
|
||||
import { build } from 'tsdown'
|
||||
import gulp from 'gulp'
|
||||
import { build } from 'tsdown';
|
||||
import gulp from 'gulp';
|
||||
|
||||
gulp.task('build', async () => {
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
dts: true,
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('watch', () => {
|
||||
return gulp.watch('src/**/*.ts', gulp.series('build'))
|
||||
})
|
||||
return gulp.watch('src/**/*.ts', gulp.series('build'));
|
||||
});
|
||||
```
|
||||
|
||||
### With Custom CLI
|
||||
|
||||
```ts
|
||||
// scripts/cli.ts
|
||||
import { build } from 'tsdown'
|
||||
import { Command } from 'commander'
|
||||
import { build } from 'tsdown';
|
||||
import { Command } from 'commander';
|
||||
|
||||
const program = new Command()
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.command('build')
|
||||
@@ -277,19 +283,19 @@ program
|
||||
format: ['esm', 'cjs'],
|
||||
minify: options.prod,
|
||||
sourcemap: !options.prod,
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
program.parse()
|
||||
program.parse();
|
||||
```
|
||||
|
||||
### With CI/CD
|
||||
|
||||
```ts
|
||||
// .github/scripts/build.ts
|
||||
import { build } from 'tsdown'
|
||||
import { build } from 'tsdown';
|
||||
|
||||
const isCI = process.env.CI === 'true'
|
||||
const isCI = process.env.CI === 'true';
|
||||
|
||||
await build({
|
||||
entry: ['src/index.ts'],
|
||||
@@ -297,7 +303,7 @@ await build({
|
||||
dts: true,
|
||||
minify: isCI,
|
||||
clean: true,
|
||||
})
|
||||
});
|
||||
|
||||
// Upload to artifact storage
|
||||
if (isCI) {
|
||||
@@ -309,15 +315,15 @@ if (isCI) {
|
||||
|
||||
```ts
|
||||
// scripts/build.ts
|
||||
import { build, type UserConfig } from 'tsdown'
|
||||
import { build, type UserConfig } from 'tsdown';
|
||||
|
||||
const config: UserConfig = {
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
dts: true,
|
||||
}
|
||||
};
|
||||
|
||||
await build(config)
|
||||
await build(config);
|
||||
```
|
||||
|
||||
## Tips
|
||||
@@ -334,6 +340,7 @@ await build(config)
|
||||
### Import Errors
|
||||
|
||||
Ensure tsdown is installed:
|
||||
|
||||
```bash
|
||||
pnpm add -D tsdown
|
||||
```
|
||||
@@ -341,31 +348,38 @@ pnpm add -D tsdown
|
||||
### Type Errors
|
||||
|
||||
Import types:
|
||||
|
||||
```ts
|
||||
import type { UserConfig } from 'tsdown'
|
||||
import type { UserConfig } from 'tsdown';
|
||||
```
|
||||
|
||||
### Build Fails Silently
|
||||
|
||||
Add error handling:
|
||||
|
||||
```ts
|
||||
try {
|
||||
await build(config)
|
||||
await build(config);
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
```
|
||||
|
||||
### Options Not Working
|
||||
|
||||
Check spelling and types:
|
||||
|
||||
```ts
|
||||
// ✅ Correct
|
||||
{ format: ['esm', 'cjs'] }
|
||||
{
|
||||
format: ['esm', 'cjs'];
|
||||
}
|
||||
|
||||
// ❌ Wrong
|
||||
{ formats: ['esm', 'cjs'] }
|
||||
{
|
||||
formats: ['esm', 'cjs'];
|
||||
}
|
||||
```
|
||||
|
||||
## Related
|
||||
|
||||
Reference in New Issue
Block a user