Rsdoctor Documentation
repository·main·Indexed 22 days ago
https://github.com/web-infra-dev/rsdoctorA 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.
What's inside Rsdoctor
- @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.
Overview of Rsdoctor
mainRsdoctor 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.
Overview of Rsdoctor build features
mainRsdoctor 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.
What is Rsdoctor
mainRsdoctor 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.Use @rsdoctor/client for Rsdoctor reporting
main@rsdoctor/client is the reporting platform for Rsdoctor. It is responsible for visualizing and presenting the build analysis data generated by Rsdoctor.Analyze build artifacts with the Bundle Size module
mainRsdoctor's
Bundle Sizemodule 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.
Available Rsdoctor example configurations
mainThe 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.
Understand Rsdoctor build terminology: assets, chunks, and modules
mainTo 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
indexmight contain bothindex.jsandindex.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.jsorstyle.cssare modules. They are not the final artifacts themselves, but they are the building blocks that participate in the packaging process.
- Examples:
View Module details (Reasons, Dependencies, and Bailout)
mainClicking 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.
- Reasons: Shows why a module exists by displaying the upstream reference chain (which modules import this module). This corresponds to Rspack's
Understand the Compile Overall overview card
mainThe
Compile Overallcard 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.
Understand Loader timing inaccuracies
mainLoader timing data provided by Rsdoctor is an estimated time. Accurate measurement is difficult because:
- Loaders can be asynchronous or synchronous.
- Bundlers parallelize execution of non-conflicting loaders.
- JavaScript is single-threaded, so loaders compete for the task queue.
- Asynchronous logic within a loader might span across the execution of other loaders.
Note that timing for plugins like
CssExtractRspackPluginmay appear high because the loader waits for other asynchronous loaders to complete during its pitch phase.Analyze Concatenated Modules
mainConcatenated 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-maphidden-source-mapinline-source-mapcheap-source-mapcheap-module-source-mapnosources-source-map
export default { // ... devtool: 'cheap-source-map', // Required for webpack concatenated module analysis };