For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/guides/basic-features/debug/rsdoctor.md.
  • 简体中文
  • 使用 Rsdoctor

    Rsdoctor 是一个 Rspack 构建分析工具。在 Modern.js 中,我们推荐使用 Rsdoctor 来对构建过程与构建产物进行诊断和分析。

    安装依赖

    npm
    yarn
    pnpm
    bun
    deno
    npm add @rsdoctor/rspack-plugin -D

    注册插件

    在 modern.config.ts 中,你可以通过 tools.bundlerChain 来注册 Rspack 插件,参考:

    modern.config.ts
    import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
    
    export default {
      // ...
      tools: {
        bundlerChain(chain) {
          // 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
          if (process.env.RSDOCTOR) {
            chain.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
              {
                // 插件选项
              },
            ]);
          }
        },
      },
    };

    执行构建

    你可以在项目内执行 build 命令,在完成构建后,Rsdoctor 会自动打开本次构建的分析页面。

    RSDOCTOR=true npm run build

    相关文档

    更多内容请查阅 Rsdoctor 官网文档。