---
title: "@farmfe/js-plugin-dts"
locale: "zh"
version: "1.x"
canonicalUrl: "https://farmfe.org/zh/docs/1.x/plugins/official-plugins/js-dts"
publicationStatus: "prerelease"
---

<a id="farmfejs-plugin-dts"></a>
# @farmfe/js-plugin-dts


支持 ` .d.ts ` 文件。 该插件用于构建的工具库，为您的 ts 代码生成“.d.ts”


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install @farmfe/js-plugin-dts
```


**yarn**

```javascript
yarn add @farmfe/js-plugin-dts
```


**pnpm**

```javascript
pnpm add @farmfe/js-plugin-dts
```



<a id="usage"></a>
## Usage


```ts
import { UserConfig } from '@farmfe/core';
import farmJsPluginDts from '@farmfe/js-plugin-dts';

const config: UserConfig = {
  plugins: [
    farmJsPluginDts({ /* options */ })
  ]
}
```


<a id="options"></a>
## Options


```ts
import type { ts, Diagnostic } from 'ts-morph';

export interface DtsPluginOptions {
  /**
   * Depends on the root directory
   */
  root?: string;

  /**
   * Declaration files output directory
   */
  outputDir?: string | string[];

  /**
   * set the root path of the entry files
   */
  entryRoot?: string;

  /**
   * Project init compilerOptions using by ts-morph
   */
  compilerOptions?: ts.CompilerOptions | null;

  /**
   * Project init tsconfig.json file path by ts-morph
   */
  tsConfigPath?: string;

  /**
   * set include glob
   */
  include?: string | string[];

  /**
   * set exclude glob
   */
  exclude?: string | string[];

  /**
   * Whether copy .d.ts source files into outputDir
   *
   * @default false
   */
  copyDtsFiles?: boolean;

  /**
   * Whether emit nothing when has any diagnostic
   *
   * @default false
   */
  noEmitOnError?: boolean;

  /**
   * Whether skip typescript diagnostics
   *
   * @default true
   */
  skipDiagnostics?: boolean;

  /**
   * Customize typescript lib folder path
   *
   * @default undefined
   */
  libFolderPath?: string;

  /**
   * According to the length to judge whether there is any type error
   */
  afterDiagnostic?: (diagnostics: Diagnostic[]) => void | Promise<void>;
}

```
