Use Rsdoctor

Rsdoctor is a build analyzer that can visually display the build process, such as compilation time, code changes before and after compilation, module reference relationships, duplicate modules, etc.

If you need to debug the build outputs or build process, you can use Rsdoctor for troubleshooting.

Quick Start

In a Rsbuild-based project, you can enable Rsdoctor as follows:

  1. Install the Rsdoctor plugin:
npm
yarn
pnpm
bun
npm add @rsdoctor/rspack-plugin -D
  1. Add RSDOCTOR=true env variable before the CLI command:
package.json
{
  "scripts": {
    "dev:rsdoctor": "RSDOCTOR=true rsbuild dev",
    "build:rsdoctor": "RSDOCTOR=true rsbuild build"
  }
}

Since the Windows system does not support the above usage, you can also use cross-env to set environment variables. This ensures compatibility across different systems:

package.json
{
  "scripts": {
    "dev:rsdoctor": "cross-env RSDOCTOR=true rsbuild dev",
    "build:rsdoctor": "cross-env RSDOCTOR=true rsbuild build"
  },
  "devDependencies": {
    "cross-env": "^7.0.0"
  }
}

After running the above commands, Rsbuild will automatically register the Rsdoctor plugin, and after the build is completed, it will open the build analysis page. For complete features, please refer to Rsdoctor document.

Options

If you need to configure the options provided by the Rsdoctor plugin, please manually register the Rsdoctor plugin:

rsbuild.config.ts
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';

export default {
  tools: {
    rspack(config, { appendPlugins }) {
      if (process.env.RSDOCTOR === 'true') {
        appendPlugins(
          new RsdoctorRspackPlugin({
            // plugin options
          }),
        );
      }
    },
  },
};
ON THIS PAGE