For AI agents: the complete documentation index is available at https://rslib.rs/zh/llms.txt, the full documentation bundle is available at https://rslib.rs/zh/llms-full.txt, and this page is available as Markdown at https://rslib.rs/zh/guide/advanced/rsdoctor.md.
close
  • 简体中文
  • 使用 Rsdoctor

    Rsdoctor 是为 Rspack 生态打造的构建分析工具,通过可视化呈现构建过程与产物,帮助开发者排查构建问题、定位性能瓶颈;同时为 Agent 提供构建数据,支持对 JavaScript 程序的自动诊断与优化。

    快速上手

    在基于 Rslib 的项目中,你可以通过以下步骤开启 Rsdoctor 分析:

    1. 安装 Rsdoctor 插件:
    npm
    yarn
    pnpm
    bun
    deno
    npm add @rsdoctor/core@latest -D

    从 Rsdoctor 1.x 升级,请参考 Rsdoctor 2.0 迁移指南。

    1. 在 CLI 命令前添加 RSDOCTOR=true 环境变量:
    package.json
    {
      "scripts": {
        "build:rsdoctor": "RSDOCTOR=true rslib"
      }
    }

    由于 Windows 不支持上述用法,你也可以使用 cross-env 来设置环境变量,这可以确保在不同的操作系统中都能正常使用:

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

    在项目内执行上述命令后,Rslib 会自动注册 Rsdoctor 的插件,并在构建完成后打开本次构建的分析页面,参考 Rsdoctor 文档 来了解完整功能。

    配置项

    如果你需要配置 Rsdoctor 插件提供的 选项,可以手动注册 Rsdoctor 插件:

    rslib.config.ts
    import { RsdoctorRspackPlugin } from '@rsdoctor/core';
    import { defineConfig } from '@rslib/core';
    
    export default defineConfig({
      tools: {
        rspack: {
          plugins: [
            process.env.RSDOCTOR === 'true' &&
              new RsdoctorRspackPlugin({
                // 插件选项
              }),
          ],
        },
      },
    });