Skip to content

Getting Started

Overview

Dtsbuild is a bundler for TypeScript declaration files. It can bundle .d.ts files (emitted by tsc) into a single file or multiple chunks for multiple entry points.

Bundling helps libraries that generate types to strip out internal and non-public types, resulting in smaller package sizes and less unnecessary types being exposed. It can also bundle types from external dependencies if only a subset of types are used.

See how dtsbuild compares with other existing toolings.

Project status

Beta. Not production ready, but usable for testing and feedback.

  • Bundles most project types correctly, however bugs are expected.
  • Missing features such as sourcemaps, good error reporting, and plugin support (with .e.g. vue-tsc, svelte2tsx, etc).
  • Supports few popular OS architectures only for now:
    • x86_64-apple-darwin
    • aarch64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
    • wasm32-wasip1-threads

Installation

bash
$ npm install -D @dtsbuild/core
bash
$ yarn add -D @dtsbuild/core
bash
$ pnpm add -D @dtsbuild/core

Run the dtsbuild CLI command:

bash
$ npx dtsbuild ./index.d.ts
bash
$ yarn dtsbuild ./index.d.ts
bash
$ pnpm dtsbuild ./index.d.ts

To invoke programmatically, create a new build script file, e.g. build-dts.mjs:

js
import { build } from '@dtsbuild/core'

await build({
  entryPoints: ['./index.d.ts'],
})

And run the script with Node.js:

bash
$ node build-dts.mjs

To bundle .ts files, check out the usage guide for setup details and other common usage examples.