Rsdoctor Documentation

repository·main·Indexed 22 days ago

https://github.com/web-infra-dev/rsdoctor

A build analyzer tailored for the Rspack ecosystem and fully compatible with webpack. Rsdoctor provides visualization and deep analysis of build artifacts and processes, including compilation behavior, resource lists, module dependencies, and build-time analysis for Loaders, Plugins, and Resolvers. It supports frameworks such as Rsbuild, Rspress, Rslib, Docusaurus, Next.js, and Nuxt. The ecosystem includes @rsdoctor/core for plugin development, @rsdoctor/client for reporting, @rsdoctor/cli for profile analysis, and @rsdoctor/agent-cli for programmatic access to analysis data.

Tokens
54K
Snippets
164
Records
295
Agent score
78%

What's inside Rsdoctor

  1. What is @rsdoctor/core?

    main
    @rsdoctor/core is the central package of the Rsdoctor ecosystem. It provides the essential tools and analysis capabilities required to build and run Rsdoctor plugins. If you are developing custom plugins to extend Rsdoctor's analysis or build capabilities, this is the package you will interact with.
  2. Overview of Rsdoctor

    main

    Rsdoctor is a build analyzer designed for the Rspack ecosystem and is fully compatible with the webpack ecosystem. It provides a one-stop, intelligent analysis platform to make build processes transparent and optimizable through visualization.

    Key capabilities include:

    • Compilation Visualization: Visualizes compilation behavior and time consumption to identify build issues.
    • Build Artifact Analysis: Supports analyzing resource lists, module dependencies, and more.
    • Build-time Analysis: Analyzes the building process for Loaders, Plugins, and Resolvers.
    • Anti-degradation/Build Rules: Includes built-in rules like duplicate package detection and ES Version Check.
    • Custom Rules: Allows users to add custom component scan rules based on Rsdoctor build data.
  3. Overview of Rsdoctor build features

    main

    Rsdoctor provides comprehensive visibility into the build process through three main lenses: Build Overview, Compilation Analysis, and Bundle Analysis.

    Build Overview

    Provides high-level information about the project state and artifacts:

    • Project Overview: View current project configuration and version.
    • Bundle Overview: View information about the artifacts built for the current project.
    • Compilation Overview: View data regarding the current project's compilation process.
    • Bundle Alert: Detect issues based on build artifact data.
    • Compilation Alert: Detect issues based on compilation data.
  4. What is Rsdoctor

    main
    Rsdoctor is a build analyzer designed for the Rspack ecosystem and is fully compatible with webpack. It provides a one-stop, intelligent visualization and analysis platform to make the build process transparent and predictable. It helps development teams identify performance bottlenecks, optimize build times, and improve engineering quality through detailed diagnostics and artifact analysis.
  5. Analyze build artifacts with the Bundle Size module

    main

    Rsdoctor's Bundle Size module allows you to analyze Webpack or Rspack build artifacts. It provides insights into resource sizes, duplicate packages, and module reference relationships.

    Key features include:

    • Bundle Overview: A high-level summary of total artifacts, file type distribution (size and count), and duplicate packages.
    • Bundle Analysis Module: A deep dive into the size and code of Assets (output files like JS, CSS, images) and Modules (the building blocks of chunks). It shows actual code size after packaging, original source code, and packaged code segments.

    The analysis is presented in two primary view modes:

    • Tree Map: A visual composition view showing the proportion of resources and modules. Supports zooming into module areas and searching.
    • Tree Graph: A file tree-based view for visualizing the composition of artifacts and modules. Supports searching and viewing module details/code directly.
  6. Available Rsdoctor example configurations

    main

    The repository includes several example directories to demonstrate different integration scenarios:

    • rspack-minimal/: A basic Rspack setup integrated with Rsdoctor.
    • rspack-banner-minimal/: Rspack configuration including a banner plugin.
    • rspack-layers-minimal/: Rspack configuration with layer support.
    • rsbuild-minimal/: An Rsbuild setup integrated with Rsdoctor.
  7. Understand Rsdoctor build terminology: assets, chunks, and modules

    main

    To effectively use Rsdoctor's analysis and plugin features, it is important to distinguish between the different units of a build process:

    assets (Resources | Artifact Files)

    Assets are the final static files output to your target directory after a build. These are the files eventually loaded by the browser.

    • Examples: logo.png, main.css, app.js.

    chunk

    A chunk is a bundle created by Rspack by packaging multiple modules together. A single chunk can contain one or more assets.

    • Example: A chunk named index might contain both index.js and index.css.

    module

    Modules are the smallest units in the build process. In Rspack, almost any file (JS, CSS, images, etc.) is considered a module. Rspack organizes these through a dependency graph to eventually compose them into assets.

    • Examples: Source files like index.js or style.css are modules. They are not the final artifacts themselves, but they are the building blocks that participate in the packaging process.
  8. View Module details (Reasons, Dependencies, and Bailout)

    main

    Clicking a module tag opens the module details view, which provides:

    • Reasons: Shows why a module exists by displaying the upstream reference chain (which modules import this module). This corresponds to Rspack's stats.reasons.
    • Dependencies: Lists the modules that the current module depends on.
    • Bailout Reason: Explains why a module failed Tree Shaking.
  9. Understand the Compile Overall overview card

    main

    The Compile Overall card on the Rsdoctor homepage provides a high-level summary of your project's compilation process. It breaks down the total time into specific phases.

    Key Interaction: If the time data for a phase is displayed in blue, it is interactive. You can click on it to view a detailed breakdown of that specific phase's timing and hook execution.

  10. Understand Loader timing inaccuracies

    main

    Loader timing data provided by Rsdoctor is an estimated time. Accurate measurement is difficult because:

    1. Loaders can be asynchronous or synchronous.
    2. Bundlers parallelize execution of non-conflicting loaders.
    3. JavaScript is single-threaded, so loaders compete for the task queue.
    4. Asynchronous logic within a loader might span across the execution of other loaders.

    Note that timing for plugins like CssExtractRspackPlugin may appear high because the loader waits for other asynchronous loaders to complete during its pitch phase.

  11. Analyze Concatenated Modules

    main

    Concatenated modules are multiple modules merged into a single closure. Rsdoctor supports analyzing these to identify the real bundled size of sub-modules, which is critical for optimizing code splitting.

    Rspack Projects

    For Rspack projects using version >= 1.4.11, the built-in Rsdoctor plugin has enhanced sourcemap capabilities that allow seamless analysis of concatenated modules without needing to manually enable source maps.

    Webpack Projects

    For webpack projects, you must enable source maps to accurately decompose and analyze concatenated modules. Supported configurations include:

    • source-map
    • hidden-source-map
    • inline-source-map
    • cheap-source-map
    • cheap-module-source-map
    • nosources-source-map
    export default {
      // ...
      devtool: 'cheap-source-map', // Required for webpack concatenated module analysis
    };