npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rsbuild-plugin-dts

v0.18.4

Published

Rsbuild plugin that supports emitting declaration files for TypeScript.

Readme

rsbuild-plugin-dts

An Rsbuild plugin to emit declaration files for TypeScript which is built-in in Rslib.

Using in Rslib

Read Declaration files and lib.dts for more details.

Using in Rsbuild

Install:

npm add rsbuild-plugin-dts -D

Add plugin to rsbuild.config.ts:

// rsbuild.config.ts
import { pluginDts } from 'rsbuild-plugin-dts';

export default {
  plugins: [pluginDts()],
};

Options

bundle

  • Type: boolean
  • Default: false

Whether to bundle the declaration files.

If you want to bundle declaration files files, you should:

  1. Install @microsoft/api-extractor as a development dependency, which is the underlying tool used for bundling declaration files.
npm add @microsoft/api-extractor -D
  1. Set bundle to true.
pluginDts({
  bundle: true,
});

bundle.bundledPackages

  • Type: string[]

Specifies the dependencies whose declaration files should be bundled. This configuration is passed to the bundledPackages option of @microsoft/api-extractor.

By default, rsbuild-plugin-dts determines externalized dependencies based on the following configurations.

Direct dependencies (declared in package.json) that are not externalized will be automatically added to bundledPackages, and their declaration files will be bundled into the final output.

When the default behavior does not meet the requirements, you can explicitly specify the dependencies whose declaration files need to be bundled through bundle.bundledPackages. After setting this configuration, the above default behavior will be completely overwritten.

This is typically used for bundling transitive dependencies (dependencies of direct dependencies). For example, if the project directly depends on foo, and foo depends on bar, you can bundle both foo and bar's declaration files as follows:

pluginDts({
  bundle: {
    bundledPackages: ['foo', 'bar'],
  },
});

bundledPackages can be specified with the minimatch syntax, but will only match the declared direct dependencies in package.json.

distPath

  • Type: string

The output directory of declaration files. The default value follows the priority below:

  1. The distPath value of the plugin options.
  2. The declarationDir value in the tsconfig.json file.
  3. The output.distPath or output.distPath.root value of Rsbuild configuration.
pluginDts({
  distPath: './dist-types',
});

build

  • Type: boolean
  • Default: false

Whether to generate declaration files with building the project references. This is equivalent to using the --build flag with the tsc command. See Project References for more details.

When the project references are configured but the referenced project has not been built separately (for example, the source code of other projects is directly referenced in monorepo, but the corresponding declaration file is missing in the project), this option needs to be enabled to ensure that the declaration files of referenced projects can be generated correctly, thereby ensuring the integrity of the type system.

When this option is enabled, you must explicitly set declarationDir or outDir in tsconfig.json in order to meet the build requirements.

abortOnError

  • Type: boolean
  • Default: true

Whether to abort the build process when an error occurs during declaration files generation.

By default, type errors will cause the build to fail.

When abortOnError is set to false, the build will still succeed even if there are type issues in the code.

pluginDts({
  abortOnError: false,
});

dtsExtension

  • Type: string
  • Default: '.d.ts'

The extension of the declaration file.

pluginDts({
  dtsExtension: '.d.mts',
});

When tsgo is enabled, if the project also enables build or emits declaration files with different extensions to the same directory, dtsExtension may not work correctly.

alias

  • Type: Record<string, string>
  • Default: {}

Configure the path alias for declaration files.

alias will be merged with compilerOptions.paths configured in tsconfig.json and alias has a higher priority.

In most cases, you don't need to use alias, but consider using it when you need to use path alias only in declaration files without wanting to affect JavaScript outputs. For example, map the declaration file of foo to ./compiled/foo.

pluginDts({
  alias: {
    foo: './compiled/foo',
  },
});

autoExternal

  • Type: boolean
  • Default: true

Whether to automatically externalize dependencies of different dependency types and do not bundle them into the declaration file.

The default value of autoExternal is true, which means the following dependency types will not be bundled:

  • dependencies
  • optionalDependencies
  • peerDependencies

And the following dependency types will be bundled:

  • devDependencies
pluginDts({
  autoExternal: {
    dependencies: true,
    optionalDependencies: true,
    peerDependencies: true,
    devDependencies: false,
  },
});

banner

  • Type: string
  • Default: undefined

Inject content into the top of each declaration file.

pluginDts({
  banner: '/** @banner */',
});

footer

  • Type: string
  • Default: undefined

Inject content into the bottom of each declaration file.

pluginDts({
  footer: '/** @footer */',
});

redirect

  • Type:
type DtsRedirect = {
  path?: boolean;
  extension?: boolean;
};
  • Default:
const defaultRedirect = {
  path: true,
  extension: false,
};

Controls the redirect of the import paths of TypeScript declaration output files.

pluginDts({
  redirect: {
    path: true,
    extension: false,
  },
});

redirect.path

  • Type: boolean
  • Default: true

Whether to automatically redirect the import paths of TypeScript declaration output files.

  • When set to true, Rslib will redirect the import path in the declaration output file to the corresponding relative path based on the compilerOptions.paths configured in tsconfig.json.
// `compilerOptions.paths` is set to `{ "@/*": ["src/*"] }`
import { foo } from '@/foo'; // source code of './src/bar.ts' ↓
import { foo } from './foo'; // expected output of './dist/bar.d.ts'

import { foo } from '@/foo'; // source code of './src/utils/index.ts' ↓
import { foo } from '../foo'; // expected output './dist/utils/index.d.ts'
  • When set to false, the original import path will remain unchanged.

redirect.extension

  • Type: boolean
  • Default: false

Whether to automatically redirect the file extension of import paths based on the TypeScript declaration output files.

  • When set to true, the file extension of the import path in the declaration file will be automatically completed or replaced with the corresponding JavaScript file extension that can be resolved to the corresponding declaration file. The extension of the declaration output file is related to the dtsExtension configuration.
// `dtsExtension` is set to `.d.mts`
import { foo } from './foo'; // source code of './src/bar.ts' ↓
import { foo } from './foo.mjs'; // expected output of './dist/bar.d.mts'

import { foo } from './foo.ts'; // source code of './src/bar.ts' ↓
import { foo } from './foo.mjs'; // expected output of './dist/bar.d.mts'
  • When set to false, import paths will retain their original file extensions.

tsgo

  • Type: boolean
  • Default: false

Whether to generate declaration files with tsgo, which can provide faster generation of declaration files, especially for large projects.

This feature is currently an experimental feature. Since tsgo is still in the experimental stage, there may be some bugs and unresolved issues or limitations. So, make sure to fully test it in your project before enabling this option.

To enable this option, you need to:

  1. Install @typescript/native-preview as a development dependency.
npm add @typescript/native-preview -D

@typescript/native-preview requires Node.js 20.6.0 or higher.

  1. Set tsgo to true.
pluginDts({
  tsgo: true,
});
  1. In order to ensure the consistency of local development, you need to install the corresponding VS Code Preview Extension and add the following configuration in the VS Code settings:
{
  "typescript.experimental.useTsgo": true
}

Contributing

Please read the Contributing Guide.

License

MIT licensed.