> For AI agents: the complete documentation index is available at https://rspack.rs/zh/llms.txt, the full documentation bundle is available at https://rspack.rs/zh/llms-full.txt.

# 产物分析

## Rsdoctor 的产物分析

[Rsdoctor](https://rspack.rs/zh/guide/diagnostics/use-rsdoctor.md) 提供了 `Bundle Size` 模块，该模块主要用于分析 Rspack 构建产物的信息，包括当前编译产物的资源大小、重复包、模块引用关系等：

- **产物概览**：展示产物总数、各类型文件数目、大小以及占比，以及重复包和重复包的引用链；
- **产物分析（`Bundle Analysis`）模块**：分析构建产物资源（**Assets**）以及所包含的 **Modules** 的大小和代码信息。在该模块中，可以查看 Assets 中 **Module 打包后的实际代码大小**，以及模块的原始代码或**打包后的代码段**以及**模块引用关系**。

![](https://assets.rspack.rs/others/assets/rsdoctor/bundle-size-overall.png)
点击**导航栏 「Bundle Size」-> 「Bundle Size」选项**，即可查看 Bundle 分析报告。详细文档可查看[Bundle Size](https://rsdoctor.rs/zh/guide/usage/bundle-size)

### 重复包治理

在生产构建中，优化包大小是一个重要环节，因为它直接影响到在线用户的使用体验。

- 检查重复包：

你可以使用 Rsdoctor 来检测项目中是否存在重复的第三方依赖包。Rsdoctor 在构建过程中进行分析，找到重复依赖包并以可视化方式显示出来：

![](https://assets.rspack.rs/others/assets/rsdoctor/overall-alerts.jpg)

更多的细节, 可以查看 [Rsdoctor - 重复包治理](https://rsdoctor.rs/zh/blog/topic/duplicate-pkg-problem).

## bundle-stats & statoscope

你也可以生成 stats.json 文件，用其他包解析工具进一步分析，如 [bundle-stats](https://github.com/relative-ci/bundle-stats) 或 [statoscope](https://github.com/statoscope/statoscope)。

```sh
$ rspack build --json stats.json
```
