Skip to content

base

npm version License: MIT Node.js tsup

> [!WARNING] > Deprecated and no longer maintained. tsup is maintenance-only and recommends tsdown. Use @jmlweb/tsdown-config-base: same helper API and published file names, with a migration guide.

> Base tsup configuration for jmlweb projects, with sensible defaults for TypeScript libraries and CLIs.

  • 🎯 Sensible defaults: Pre-configured for TypeScript libraries
  • 📦 Dual format: CommonJS and ESM output by default
  • 📝 Declarations: .d.ts generation enabled
  • 🖥️ CLI preset: Shebang support
  • 🛠️ Fully typed: Exported option types
Terminal window
npm install --save-dev @jmlweb/tsup-config-base tsup

Create tsup.config.ts in your project root:

import { createTsupConfig } from '@jmlweb/tsup-config-base';
export default createTsupConfig();
import { createTsupConfig } from '@jmlweb/tsup-config-base';
export default createTsupConfig({
external: ['@jmlweb/eslint-config-base-js', '@eslint/js', 'eslint'],
});
import { createTsupConfig } from '@jmlweb/tsup-config-base';
export default createTsupConfig({
entry: { index: 'src/index.ts', utils: 'src/utils/index.ts' },
external: ['commander'],
options: {
minify: true,
sourcemap: true,
},
});
import { createTsupCliConfig } from '@jmlweb/tsup-config-base';
export default createTsupCliConfig();
// Output: dist/cli.js with a #!/usr/bin/env node shebang
import { createTsupCliConfig } from '@jmlweb/tsup-config-base';
export default createTsupCliConfig({
entry: { cli: 'src/cli.ts', index: 'src/index.ts' },
shebang: 'cli', // Only the cli entry gets a shebang
external: ['commander'],
});
Option Type Default Description
entry string[] | Record<string, string> ['src/index.ts'] Entry point files
format ('cjs' | 'esm' | 'iife')[] ['cjs', 'esm'] Output formats
dts boolean true Generate declaration files
clean boolean true Clean output before build
outDir string 'dist' Output directory
external (string | RegExp)[] [] Packages to exclude from bundle
options Partial<Options> {} Additional tsup options to merge

createTsupCliConfig(options?): Options | Options[]

Section titled “createTsupCliConfig(options?): Options | Options[]”

Same options, with format defaulting to ['esm'] and entry to { cli: 'src/cli.ts' }, plus:

Option Type Default Description
target NodeTarget 'node18' Node.js target version
shebang boolean | string | string[] true Shebang on all entries (true) or the named ones

Returns an array of configs when a selective shebang is used.

  • createTsupConfig, createTsupCliConfig - Helpers
  • BASE_DEFAULTS, CLI_DEFAULTS - Default values
  • TsupConfigOptions, TsupCliConfigOptions, EntryConfig, NodeTarget - Types
  • Options - Re-exported from tsup

Do not use for new projects. Use @jmlweb/tsdown-config-base instead.

Only keep this package while you have not yet migrated an existing tsup-based build.

import { createTsupConfig } from '@jmlweb/tsup-config-base';
export default createTsupConfig({
format: ['esm'], // ESM only
dts: false, // No type declarations
outDir: 'build',
external: ['vitest'], // Peer, workspace and optional dependencies
options: {
minify: true,
splitting: true,
target: 'es2022',
},
});
{
"scripts": {
"build": "tsup",
"clean": "rm -rf dist",
"prepublishOnly": "npm run build"
}
}
Terminal window
npm run build # Build the package
npm run clean # Clean build output
  • Node.js >= 22.12.0
  • tsup >= 8.0.0 (tsup 9 itself requires Node.js >= 22.18.0)
  • tsup (>=8.0.0)

Breaking: Node.js >= 22.12.0 is required (18 and 20 are end-of-life).

Follow the migration guide.

See the Changelog for version history.

MIT