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

# Using Rsdoctor

Rsdoctor is a Rspack build analysis tool. In Modern.js, we recommend using Rsdoctor to diagnose and analyze the build process and build outputs.

## Install Dependencies


```sh [npm]
npm add @rsdoctor/rspack-plugin -D
```

```sh [yarn]
yarn add @rsdoctor/rspack-plugin -D
```

```sh [pnpm]
pnpm add @rsdoctor/rspack-plugin -D
```

```sh [bun]
bun add @rsdoctor/rspack-plugin -D
```

```sh [deno]
deno add npm:@rsdoctor/rspack-plugin -D
```

## Register Plugin

In `modern.config.ts`, you can register the Rspack plugin via `tools.bundlerChain`. Refer to the example below:

```ts title="modern.config.ts"
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';

export default {
  // ...
  tools: {
    bundlerChain(chain) {
      // Only register the plugin when RSDOCTOR is true, as the plugin will increase build time.
      if (process.env.RSDOCTOR) {
        chain.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
          {
            // Plugin options
          },
        ]);
      }
    },
  },
};
```

## Execute Build

You can execute the build command within your project. After the build is complete, Rsdoctor will automatically open the analysis page for the build.

```bash
RSDOCTOR=true npm run build
```

## Related Documentation

For more information, please refer to the [Rsdoctor Website](https://rsdoctor.rs/).
