> For AI agents: the complete documentation index is available at https://rspack.rs/llms.txt, the full documentation bundle is available at https://rspack.rs/llms-full.txt.

# Use Rsdoctor

[Rsdoctor](https://rsdoctor.rs/) is a build analysis tool for the Rspack ecosystem. It visualizes the build process and output to help developers investigate build issues and identify performance bottlenecks. It also provides build data to agents for automated diagnosis and optimization of JavaScript programs.

## Requirements

Rsdoctor 2.0 requires Node.js `^20.19.0 || >=22.12.0` and Rspack 2.0 or later. If your project uses Rspack 1.x or webpack, use Rsdoctor 1.x instead.

## How to use

1. Install `@rsdoctor/core`:


```sh [npm]
npm add @rsdoctor/core@latest -D
```

```sh [yarn]
yarn add @rsdoctor/core@latest -D
```

```sh [pnpm]
pnpm add @rsdoctor/core@latest -D
```

```sh [bun]
bun add @rsdoctor/core@latest -D
```

```sh [deno]
deno add npm:@rsdoctor/core@latest -D
```

To upgrade from Rsdoctor 1.x, see the [Rsdoctor 2.0 migration guide](https://rsdoctor.rs/guide/migration/migration-v2).

2. Register `RsdoctorRspackPlugin` in the Rspack [plugins](https://rspack.rs/config/plugins.md) option. Rsdoctor 2.0 packages are ESM-only, so use an ESM config and import:

```js title="rspack.config.mjs"
import { RsdoctorRspackPlugin } from '@rsdoctor/core';

export default {
  plugins: [
    // Register the plugin only when RSDOCTOR is true, as the plugin increases build time
    process.env.RSDOCTOR &&
      new RsdoctorRspackPlugin({
        // plugin options
      }),
  ],
};
```

3. Set `RSDOCTOR=true` when running Rspack:

```bash
RSDOCTOR=true rspack serve
RSDOCTOR=true rspack build
```

On Windows, use [cross-env](https://npmjs.com/package/cross-env) to set environment variables:

```bash
cross-env RSDOCTOR=true rspack serve
cross-env RSDOCTOR=true rspack build
```

After the build, Rsdoctor opens the analysis page. See the [Rsdoctor 2.0 quick start](https://rsdoctor.rs/guide/start/quick-start) for more details.
