@rsdoctor/docs 1.0.0-rc.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,11 +23,11 @@ Rsdoctor is a one-stop build analysis tool for Rspack and Webpack. It allows for
23
23
  - **Compilation Visualization**: Rsdoctor visualizes the compilation behavior and time consumption, making it easy to view build issues.
24
24
  - **Multiple Analysis Capabilities**: Rsdoctor supports build artifact, build-time analysis, and anti-degradation capabilities:
25
25
  - Build artifact support for resource lists and module dependencies, etc.
26
- - Build-time analysis supports Loader, Plugin, and Resolver building process analysis, including: Rspack's builtin:swc-loader.
26
+ - Build-time analysis supports Loader, Plugin, and Resolver building process analysis, including Rspack's builtin loaders.
27
27
  - Build rules support duplicate package detection and ES Version Check, etc.
28
- - Currently, bundle Diff capabilities are also available.
28
+ - Currently, bundle diff capabilities are also available.
29
29
  - **Support Custom Rules**: In addition to built-in build scan rules, Rsdoctor also supports users adding custom component scan rules based on the build data of Rsdoctor.
30
- - **Framework-Independent**: Rsdoctor support all projects built on Webpack or Rspack.
30
+ - **Framework-Independent**: Rsdoctor support all projects built on Rspack or webpack.
31
31
 
32
32
  ## 🛠️ Introduction
33
33
 
@@ -48,7 +48,7 @@ Provides corresponding data and analysis functions for **Loaders, Plugins, and M
48
48
 
49
49
  #### Loader analysis
50
50
 
51
- - This module mainly provides the function of data analysis such as input and output, estimated time consumption, and parameters within **Rspack or Webpack Loaders**.
51
+ - This module mainly provides the function of data analysis such as input and output, estimated time consumption, and parameters within **Rspack or webpack Loaders**.
52
52
 
53
53
  <div style={{ display: 'flex' }}>
54
54
  <img
@@ -78,7 +78,8 @@ export default {
78
78
 
79
79
  ## Support for banner plugin
80
80
 
81
- Both Rspack and Webpack support the BannerPlugin, which is an built-in plugin that allows you to add specific content at the top or bottom of the generated chunks. The added code will affect the parsing capability of the bundle.
81
+ Both Rspack and webpack support the BannerPlugin, which is an built-in plugin that allows you to add specific content at the top or bottom of the generated chunks. The added code will affect the parsing capability of the bundle.
82
+
82
83
  Therefore, Rsdoctor has added support for the Banner Plugin.
83
84
 
84
85
  Please refer to [Support for BannerPlugin](/guide/usage/bundle-size#support-for-bannerplugin)
@@ -3,7 +3,7 @@
3
3
  import NextSteps from '@components/NextSteps';
4
4
  import Step from '@components/Step';
5
5
 
6
- Optimizing loaders is a common way to improve the performance of Rspack or Webpack compilation. In most cases, besides replacing the loader with a faster one, we can also reduce execution by setting [module.rule.exclude](https://webpack.js.org/configuration/module/#ruleexclude) for the loader.
6
+ Optimizing loaders is a common way to improve the performance of Rspack or webpack compilation. In most cases, besides replacing the loader with a faster one, we can also reduce execution by setting [module.rule.exclude](https://webpack.js.org/configuration/module/#ruleexclude) for the loader.
7
7
 
8
8
  Rsdoctor provides two core modules, [Loader Overall](/guide/usage/loaders-timeline) and [Loader Analysis](/guide/usage/loaders-analysis), to help you optimize based on the loader's invocation information.
9
9
 
@@ -175,7 +175,7 @@ Therefore, **the default configuration enables bundle analysis capabilities and
175
175
 
176
176
  #### RsdoctorWebpackPluginFeatures
177
177
 
178
- `features` type
178
+ `features` type:
179
179
 
180
180
  import Features from '@en/shared/features.md';
181
181
 
@@ -183,7 +183,7 @@ import Features from '@en/shared/features.md';
183
183
 
184
184
  #### RsdoctorRspackPluginFeatures
185
185
 
186
- `features` type
186
+ `features` type:
187
187
 
188
188
  import FeaturesRspack from '@en/shared/features-rspack.md';
189
189
 
@@ -68,45 +68,3 @@ When using Rsdoctor to analyze the compilation time of Rspack projects, you may
68
68
  - Reason: The loader in [CssExtractRspackPlugin](https://rspack.dev/plugins/rspack/css-extract-rspack-plugin) asynchronously calls other loaders during the pitch phase and waits for the callback results after these loaders execute. Therefore, the time taken by CssExtractRspackPlugin actually includes the execution time of other loaders and idle time.
69
69
 
70
70
  <img src="https://assets.rspack.dev/rsdoctor/css-extract-loader.png" />
71
-
72
- ## Next.js
73
-
74
- ### Issue with Next.js project report page
75
-
76
- Initialize the RsdoctorWebpackPlugin plugin in the [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) of `next.config.js`.
77
-
78
- However, in Next.js, when Rsdoctor is enabled and the **build command** is executed, the report server started by Rsdoctor will be disconnected. Therefore, if you need to reopen the report, you can use **[@rsdoctor/cli](../start/cli.mdx)** without performing the build operation.
79
-
80
- For example, if the build artifact of Rsdoctor is located at the path `.next/.rsdoctor/manifest.json`, you can open the report page by executing the following command:
81
-
82
- ```bash
83
- npx @rsdoctor/cli analyze --profile .next/.rsdoctor/manifest.json
84
-
85
- ```
86
-
87
- ### Loader analysis with rule override is not supported in Next.js
88
-
89
- - Rsdoctor Loader logic: Since Rsdoctor modifies the Loader Rules, Rsdoctor wraps the Module in a Proxy to support Loader logic with rule override.
90
-
91
- - Next.js specific logic: In Next.js, the LoaderContext adds the currentTraceSpan property, which is obtained from the value retrieved using the Module as the key. However, since Rsdoctor wraps the Module in a Proxy (referred to as ProxyModule), retrieving the value using ProxyModule as the key will result in no value being obtained.
92
-
93
- Based on the above reason, Rsdoctor does not wrap the Module in a Proxy in Next.js projects, which means it does not support Loader analysis with rule override. If you encounter Loader errors, you need to configure the **[features](../../config/options/options#features)** parameter to disable **Loader** analysis. You can use the following configuration:
94
-
95
- ```js title="next.config.js"
96
- const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
97
-
98
- module.exports = {
99
- // ...
100
- webpack: (config, { isServer }) => {
101
- config.plugins.push(
102
- new RsdoctorWebpackPlugin({
103
- // 插件选项
104
- features: ['bundle', 'plugins'],
105
- }),
106
- );
107
- return config;
108
- },
109
- };
110
- ```
111
-
112
- - **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
@@ -3,20 +3,20 @@
3
3
  ## 💡 What is Rsdoctor?
4
4
 
5
5
  - Rsdoctor is a one-stop tool for diagnosing and analyzing the build process and build artifacts.
6
- - Rsdoctor is a tool that supports Webpack and Rspack build analysis.
6
+ - Rsdoctor is a tool that supports Rspack and webpack build analysis.
7
7
  - Rsdoctor is an analysis tool that can display the time-consuming and behavioral details of the compilation.
8
- - Rsdoctor is a tool that provides bundle Diff and other anti-degradation capabilities simultaneously.
8
+ - Rsdoctor is a tool that provides bundle diff and other anti-degradation capabilities simultaneously.
9
9
 
10
10
  ## 🔥 Features
11
11
 
12
12
  - **Compilation Visualization**: Rsdoctor visualizes the compilation behavior and time consumption, making it easy to view build issues.
13
13
  - **Multiple Analysis Capabilities**: Rsdoctor supports build artifact, build-time analysis, and anti-degradation capabilities:
14
14
  - Build artifact support for resource lists and module dependencies, etc.
15
- - Build-time analysis supports Loader, Plugin, and Resolver building process analysis, including: Rspack's builtin:swc-loader.
15
+ - Build-time analysis supports Loader, Plugin, and Resolver building process analysis, including Rspack's builtin loaders.
16
16
  - Build rules support duplicate package detection and ES Version Check, etc.
17
- - Currently, bundle Diff capabilities are also available.
17
+ - Currently, bundle diff capabilities are also available.
18
18
  - **Support Custom Rules**: In addition to built-in build scan rules, Rsdoctor also supports users adding custom component scan rules based on the build data of Rsdoctor.
19
- - **Framework-Independent**: Rsdoctor support all projects built on Webpack or Rspack.
19
+ - **Framework-Independent**: Rsdoctor support all projects built on Rspack or webpack.
20
20
 
21
21
  ## 🛠️ Introduction
22
22
 
@@ -36,7 +36,7 @@ Provides corresponding data and analysis functions for **Loaders, Plugins, and M
36
36
 
37
37
  #### Loader analysis
38
38
 
39
- - This module mainly provides the function of data analysis such as input and output, estimated time consumption, and parameters within Rspack / Webpack Loaders.
39
+ - This module mainly provides the function of data analysis such as input and output, estimated time consumption, and parameters within Rspack or webpack loaders.
40
40
 
41
41
  <img
42
42
  src="https://assets.rspack.dev/others/assets/rsdoctor/loader-timeline-overall.png"
@@ -75,41 +75,70 @@ export default {
75
75
  - **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
76
76
 
77
77
  :::tip
78
- For projects using Modern.js Webpack mode, please register the `RsdoctorWebpackPlugin` plugin through [tools.webpack](https://modernjs.dev/configure/app/tools/webpack).
78
+ For projects using Modern.js's webpack mode, please register the `RsdoctorWebpackPlugin` plugin through [tools.webpack](https://modernjs.dev/configure/app/tools/webpack).
79
79
  :::
80
80
 
81
81
  ### Next.js Framework
82
82
 
83
- Initialize the RsdoctorWebpackPlugin plugin in the [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) of `next.config.mjs`.
83
+ Initialize the RsdoctorWebpackPlugin plugin in the [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) of `next.config.ts`.
84
84
 
85
- ```ts title="next.config.mjs"
85
+ ```ts title="next.config.ts"
86
+ import type { NextConfig } from 'next';
86
87
  import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
87
88
 
88
- export default {
89
- // ...
90
- webpack: (config, { isServer }) => {
91
- config.plugins.push(
92
- new RsdoctorWebpackPlugin({
93
- // plugin options
94
- }),
95
- );
96
-
89
+ const nextConfig: NextConfig = {
90
+ /* config options here */
91
+ webpack: (config) => {
92
+ if (config.name === 'client') {
93
+ config.plugins.push(
94
+ new RsdoctorWebpackPlugin({
95
+ disableClientServer: true,
96
+ }),
97
+ );
98
+ } else if (config.name === 'server') {
99
+ config.plugins.push(
100
+ new RsdoctorWebpackPlugin({
101
+ disableClientServer: true,
102
+ output: {
103
+ reportDir: './.next/server',
104
+ },
105
+ }),
106
+ );
107
+ }
97
108
  return config;
98
109
  },
99
110
  };
111
+
112
+ export default nextConfig;
100
113
  ```
101
114
 
102
- - **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
115
+ - **Options:** The plugin provides some configuration options, please refer to [Options](../../config/options/options).
103
116
 
104
- #### 📢 Next.js project notice
117
+ #### 📢 Note for Next.js Projects
105
118
 
106
- 1. Next.js Project Reporting Page Issues
119
+ Since Next.js closes the terminal service after the `build` execution is completed, the report page server run by Rsdoctor during the build process will also be shut down. At this point, you can reopen the report page using [@rsdoctor/cli](/guide/start/cli) without having to execute the build operation again.
107
120
 
108
- For more details, see: [FAQ](../more/faq#nextjs)
121
+ - First, install [@rsdoctor/cli](/guide/start/cli):
109
122
 
110
- 2. Loader Analysis with Rules Overriding Not Supported in Next.js
123
+ import { PackageManagerTabs } from '@theme';
111
124
 
112
- For more details, see: [FAQ](../more/faq#nextjs)
125
+ <PackageManagerTabs command="add @rsdoctor/cli -D" />
126
+
127
+ - Second, add the following scripts commands to **package.json**, executing **client:rsdoctor** or **server:rsdoctor** can open the report for the corresponding builder:
128
+
129
+ ```ts
130
+ "scripts": {
131
+ "client:rsdoctor": "rsdoctor analyze --profile .next/.rsdoctor/manifest.json",
132
+ "server:rsdoctor": "rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json"
133
+ }
134
+ ```
135
+
136
+ For example, if Rsdoctor's build artifacts are located at the `.next/server/chunks/.rsdoctor/manifest.json` path, you can open the report page by executing the following command:
137
+
138
+ ```bash
139
+ rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json
140
+
141
+ ```
113
142
 
114
143
  ### Vue project
115
144
 
@@ -25,7 +25,7 @@ Click on the **"Bundle Size"** option in the navigation bar to view the Bundle a
25
25
  - **`Initial Chunk`**: The **initial** chunk is the main chunk of the entry point. This chunk contains all the modules specified by the entry point and their dependencies, unlike the **chunks** for "on-demand loading".
26
26
  - For more information about Initial Chunk, please refer to [Initial Chunk Introduction](https://webpack.js.org/concepts/under-the-hood/#chunks).
27
27
  - **`Duplicate Packages`**: Duplicate third-party packages bundled into the project. Excludes third-party packages that are not bundled into the artifact. Please refer to [Duplicate Packages](/guide/usage/bundle-alerts).
28
- - **`Concatenated Module`**: A concatenated module is a technique that combines multiple modules into one closure during packaging. In the past, Webpack would package each module into a separate closure, and this encapsulation function would cause slower execution of JavaScript in the browser. Optimization can be achieved by enabling the [`optimization.concatenateModules`](https://webpack.js.org/plugins/module-concatenation-plugin/#root) parameter.
28
+ - **`Concatenated Module`**: A concatenated module is a technique that combines multiple modules into one closure during packaging. In the past, Rspack would package each module into a separate closure, and this encapsulation function would cause slower execution of JavaScript in the browser. Optimization can be achieved by enabling the [`optimization.concatenateModules`](https://webpack.js.org/plugins/module-concatenation-plugin/#root) parameter.
29
29
 
30
30
  ## Bundle overview
31
31
 
@@ -144,7 +144,8 @@ Click the **"Bundle Analyzer Graph"** button on the **"Bundle Size"** page to vi
144
144
  When enabling the BannerPlugin analysis, do not use Rsdoctor in the production version.
145
145
  :::
146
146
 
147
- Both Rspack and Webpack support the [BannerPlugin](https://www.rspack.dev/plugins/webpack/banner-plugin#bannerplugin), which is a built-in plugin that allows you to add specific content at the top or bottom of the generated chunks.
147
+ Both Rspack and webpack support the [BannerPlugin](https://www.rspack.dev/plugins/webpack/banner-plugin#bannerplugin), which is a built-in plugin that allows you to add specific content at the top or bottom of the generated chunks.
148
+
148
149
  The added code segment will affect the analysis capability of the bundle.
149
150
 
150
151
  Rsdoctor is compatible with the logic of adding code using the BannerPlugin, but it is not enabled by default because Rsdoctor needs to add tag code. The Rsdoctor BannerPlugin capability is enabled in the following two cases:
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- In the **Rsdoctor** `Compile Analysis` secondary page `Plugins Analysis`, we can see the invocation data of all **Compiler Hooks** and **Compilation Hooks** used by the current Rspack or Webpack project. The content is shown in the following figure:
5
+ In the **Rsdoctor** `Compile Analysis` secondary page `Plugins Analysis`, we can see the invocation data of all **Compiler Hooks** and **Compilation Hooks** used by the current Rspack or webpack project. The content is shown in the following figure:
6
6
 
7
7
  <img
8
8
  src="https://assets.rspack.dev/others/assets/rsdoctor/plugins-analysis-overall.png"
@@ -29,7 +29,7 @@ The meanings of the fields in the data statistics table on the page are as follo
29
29
 
30
30
  ### View bundler config
31
31
 
32
- If we need to view the Rspack or Webpack configuration of the project, we can click on `View Bundler Config` in the upper right corner of the card. A floating layer will pop up, which contains the serialized **Bundler Config**, as shown in the following figure:
32
+ If we need to view the Rspack or webpack configuration of the project, we can click on `View Bundler Config` in the upper right corner of the card. A floating layer will pop up, which contains the serialized **Bundler Config**, as shown in the following figure:
33
33
 
34
34
  <img
35
35
  src="https://assets.rspack.dev/others/assets/rsdoctor/plugins-analysis-config.png"
@@ -6,31 +6,29 @@ In the main page of **Rsdoctor**, we can see a card named `Project Overall`, whi
6
6
 
7
7
  <img
8
8
  src="https://assets.rspack.dev/others/assets/rsdoctor/project-overall-1.jpg"
9
- width="400px"
10
- height="600px"
11
9
  style={{ margin: 'auto' }}
12
10
  />
13
11
 
14
12
  ## Glossary
15
13
 
16
- | Term | Description |
17
- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18
- | <b><i>errors</i></b> | Represents the **error** level rules detected by Rsdoctor during the current run |
19
- | <b><i>warns</i></b> | Represents the **warn** level rules detected by Rsdoctor during the current run |
20
- | <b><i>webpack</i></b> | Represents the Webpack version obtained during the current run |
21
- | <b><i>cwd</i></b> | Represents the current working directory during the current run, i.e., [process.cwd()](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processcwd) |
22
- | <b><i>cpu</i></b> | Represents the CPU information |
23
- | <b><i>memory</i></b> | Represents the memory information during the current run |
24
- | <b><i>node</i></b> | Represents the version number of [Node.js](https://nodejs.org/) |
25
- | <b><i>yarn</i></b> | Represents the version number of [Yarn](https://yarnpkg.com/), displayed as `Not Found` if not found |
26
- | <b><i>npm</i></b> | Represents the version number of [npm](https://www.npmjs.com/) |
27
- | <b><i>pnpm</i></b> | Represents the version number of [pnpm](https://pnpm.io/), displayed as `Not Found` if not found |
14
+ | Term | Description |
15
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
16
+ | <b><i>errors</i></b> | Represents the **error** level rules detected by Rsdoctor during the current run |
17
+ | <b><i>warns</i></b> | Represents the **warn** level rules detected by Rsdoctor during the current run |
18
+ | <b><i>rspack</i></b> | Represents the Rspack version obtained during the current run |
19
+ | <b><i>cwd</i></b> | Represents the current working directory during the current run, i.e., [process.cwd()](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processcwd) |
20
+ | <b><i>cpu</i></b> | Represents the CPU information |
21
+ | <b><i>memory</i></b> | Represents the memory information during the current run |
22
+ | <b><i>node</i></b> | Represents the version number of [Node.js](https://nodejs.org/) |
23
+ | <b><i>yarn</i></b> | Represents the version number of [Yarn](https://yarnpkg.com/), displayed as `Not Found` if not found |
24
+ | <b><i>npm</i></b> | Represents the version number of [npm](https://www.npmjs.com/) |
25
+ | <b><i>pnpm</i></b> | Represents the version number of [pnpm](https://pnpm.io/), displayed as `Not Found` if not found |
28
26
 
29
27
  ## Usage
30
28
 
31
29
  ### View bundler config
32
30
 
33
- If we need to view the Rspack or Webpack configuration of the project, we can click on `View Bundler Config` in the top right corner of the card. A popup window will appear, containing the serialized [Bundler Config](https://webpack.js.org/configuration/), as shown in the following image:
31
+ If we need to view the Rspack or webpack configuration of the project, we can click on `View Bundler Config` in the top right corner of the card. A popup window will appear, containing the serialized [Bundler Config](https://webpack.js.org/configuration/), as shown in the following image:
34
32
 
35
33
  <img
36
34
  src="https://assets.rspack.dev/others/assets/rsdoctor/project-overall-config.jpg"
@@ -17,7 +17,7 @@ new rsdoctorWebpackPlugin({
17
17
 
18
18
  :::
19
19
 
20
- In the **Rsdoctor** `Module Resolve` section, we can see all the source files in the current Webpack project. By **clicking on a file**, we can view information such as the **module paths** imported in that file, the **before and after resolution path comparison**, and the **resolution time**, as shown in the following image:
20
+ In the **Rsdoctor** `Module Resolve` section, we can see all the source files in the current Rspack project. By **clicking on a file**, we can view information such as the **module paths** imported in that file, the **before and after resolution path comparison**, and the **resolution time**, as shown in the following image:
21
21
 
22
22
  <img src="https://assets.rspack.dev/others/assets/rsdoctor/resolver.png" />
23
23
 
@@ -10,7 +10,7 @@
10
10
 
11
11
  我们很高兴地宣布 [Rsdoctor](https://rsdoctor.dev/) v0.1 发布了!
12
12
 
13
- Rsdoctor 是一个针对 Rspack 和 Webpack 的一站式构建分析工具,可以对构建时和构建产物进行详细分析,让构建过程变得可视化和透明。
13
+ Rsdoctor 是一个针对 Rspack 和 webpack 的一站式构建分析工具,可以对构建时和构建产物进行详细分析,让构建过程变得可视化和透明。
14
14
 
15
15
  ## 📌 定位
16
16
 
@@ -20,14 +20,14 @@ Rsdoctor 是一个针对 Rspack 和 Webpack 的一站式构建分析工具,可
20
20
 
21
21
  ## 🔥 特性
22
22
 
23
- - **编译可视化**:Rsdoctor 将编译行为及耗时进行可视化展示,方便开发同学查看构建问题。
23
+ - **编译可视化**:Rsdoctor 将编译行为及耗时进行可视化展示,方便开发者查看构建问题。
24
24
  - **多种分析能力**:支持构建产物、构建时分析能力:
25
25
  - 构建产物支持资源列表及模块依赖等。
26
26
  - 构建时分析支持 Loader、Plugin、Resolver 构建过程分析。
27
- - 支持 Rspack 的 builtin:swc-loader 分析。
27
+ - 支持分析 Rspack 的 builtin loaders。
28
28
  - 构建规则支持重复包检测及 ES Version Check 检查等。
29
29
  - **支持自定义规则**:除了内置构建扫描规则外,还支持用户根据 Rsdoctor 的构建数据添加自定义构建扫描规则。
30
- - **框架无关**:支持所有基于 WebpackRspack 构建的项目。
30
+ - **框架无关**:支持所有基于 Rspackwebpack 构建的项目。
31
31
 
32
32
  ## 🛠️ 功能介绍
33
33
 
@@ -75,7 +75,7 @@ export default {
75
75
 
76
76
  ## 支持 Banner plugin
77
77
 
78
- 由于 Rspack 和 Webpack 都支持 BannerPlugin,且 BannerPlugin 可在生成的 chunk 顶部或尾部添加指定内容的代码段,这会影响到对 Bundle 的解析能力。因此,Rsdoctor 增加了 Banner Plugin 的支持。
78
+ 由于 Rspack 和 webpack 都支持 BannerPlugin,且 BannerPlugin 可在生成的 chunk 顶部或尾部添加指定内容的代码段,这会影响到对 Bundle 的解析能力。因此,Rsdoctor 增加了 Banner Plugin 的支持。
79
79
 
80
80
  详情请查看[支持 BannerPlugin](/guide/usage/bundle-size#%E6%94%AF%E6%8C%81-bannerplugin)
81
81
 
@@ -3,7 +3,7 @@
3
3
  import NextSteps from '@components/NextSteps';
4
4
  import Step from '@components/Step';
5
5
 
6
- 通常来说,优化 Loader 是比较常见的优化 Rspack 或 Webpack 编译性能的方式,而大部分情况下,我们除了通过替换**更快的** `loader` 之外,常见的手段就是给 `loader` 设置 [module.rule.exclude](https://webpack.js.org/configuration/module/#ruleexclude) 来**减少执行**。
6
+ 通常来说,优化 Loader 是比较常见的优化 Rspack 或 webpack 编译性能的方式,而大部分情况下,我们除了通过替换**更快的** `loader` 之外,常见的手段就是给 `loader` 设置 [module.rule.exclude](https://webpack.js.org/configuration/module/#ruleexclude) 来**减少执行**。
7
7
 
8
8
  而 **Rsdoctor** 提供了两个核心模块([Loader Overall](/guide/usage/loaders-timeline) / [Loader Analysis](/guide/usage/loaders-analysis))来帮助你根据 Loader 的调用信息进行深度优化。
9
9
 
@@ -66,45 +66,3 @@ module.exports = {
66
66
  - 原因:[CssExtractRspackPlugin](https://rspack.dev/plugins/rspack/css-extract-rspack-plugin) 中的 loader 在 pitch 阶段会异步调用其他 loader,并等待这些 loader 执行后的回调结果。因此,CssExtractRspackPlugin 的耗时实际上包括了其他 loader 的执行时间和空闲时间。
67
67
 
68
68
  <img src="https://assets.rspack.dev/rsdoctor/css-extract-loader.png" />
69
-
70
- ## Next.js
71
-
72
- ### Next.js 项目报告页面问题
73
-
74
- 在 `next.config.js` 的 [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) 中初始化 RsdoctorWebpackPlugin 插件。
75
-
76
- 然而,在 Next.js 中,当开启 Rsdoctor 并通过 build 执行构建后,Rsdoctor 启动的报告服务器会被断开。因此,如果需要再次打开报告,可以使用 **[@rsdoctor/cli](../start/cli.mdx)**,而无需执行构建操作。
77
-
78
- 例如:Rsdoctor 的构建产物在 `.next/.rsdoctor/manifest.json` 路径,则可通过执行下面命令来打开报告页面:
79
-
80
- ```bash
81
- npx @rsdoctor/cli analyze --profile .next/.rsdoctor/manifest.json
82
-
83
- ```
84
-
85
- ### Next.js 中不支持对 rules 进行重写的 loader 分析
86
-
87
- - Rsdoctor Loader 逻辑:由于 Rsdoctor 会对 Loader Rules 做修改,所以 Rsdoctor 为了兼容对 rules 进行重写的 Loader 逻辑,Rsdoctor 对 Module 进行了 Proxy 包裹。
88
-
89
- - Next.js 特有逻辑:而 Next.js 中会对 LoaderContext 添加 currentTraceSpan 属性,这个属性的值来自于以 Module 为 key 获取的值。因为 Rsdoctor 对 Module 进行了 Proxy 包裹(简称: ProxyModule),所以以 ProxyModule 为 key 是拿不到任何值的。
90
-
91
- 基于上面原因,Rsdoctor 在 Next.js 项目中不对 Module 进行 Proxy 包裹逻辑,从而也就不支持对 rules 进行重写的 Loader 分析。如果遇到 Loader 报错,需要配置 **[features](../../config/options/options#features)** 参数来关闭 **Loader** 分析,如下配置即可:
92
-
93
- ```js title="next.config.js"
94
- const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
95
-
96
- module.exports = {
97
- // ...
98
- webpack: (config, { isServer }) => {
99
- config.plugins.push(
100
- new RsdoctorWebpackPlugin({
101
- // 插件选项
102
- features: ['bundle', 'plugins'],
103
- }),
104
- );
105
- return config;
106
- },
107
- };
108
- ```
109
-
110
- - **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
@@ -3,20 +3,20 @@
3
3
  ## 💡 什么是 Rsdoctor?
4
4
 
5
5
  - Rsdoctor 是一个面向构建过程与构建产物提供诊断和分析的一站式工具。
6
- - Rsdoctor 是一个支持 WebpackRspack 构建分析工具。
6
+ - Rsdoctor 是一个支持 Rspackwebpack 构建分析工具。
7
7
  - Rsdoctor 是一个可以展示编译耗时及编译行为细节的分析工具。
8
8
  - Rsdoctor 是一个提供 Bundle Diff 等防劣化能力的工具。
9
9
 
10
10
  ## 🔥 特性
11
11
 
12
- - **编译可视化**:Rsdoctor 将编译行为及耗时进行可视化展示,方便开发同学查看构建问题。
12
+ - **编译可视化**:Rsdoctor 将编译行为及耗时进行可视化展示,方便开发者查看构建问题。
13
13
  - **多种分析能力**:支持构建产物、构建时分析能力:
14
14
  - 构建产物支持资源列表及模块依赖等。
15
15
  - 构建时分析支持 Loader、Plugin、Resolver 构建过程分析。
16
- - 支持 Rspack 的 builtin:swc-loader 分析。
16
+ - 支持分析 Rspack 的 builtin loaders。
17
17
  - 构建规则支持重复包检测及 ES Version Check 检查等。
18
18
  - **支持自定义规则**:除了内置构建扫描规则外,还支持用户根据 Rsdoctor 的构建数据添加自定义构建扫描规则。
19
- - **框架无关**:支持所有基于 WebpackRspack 构建的项目。
19
+ - **框架无关**:支持所有基于 Rspackwebpack 构建的项目。
20
20
 
21
21
  ## 🛠️ 功能介绍
22
22
 
@@ -36,7 +36,7 @@
36
36
 
37
37
  #### Loader 分析
38
38
 
39
- - 该模块主要提供了 **Rspack 或 Webpack 的 Loaders** 内的输入输出、预估耗时、参数等数据分析的功能。
39
+ - 该模块主要提供了 **Rspack 或 webpack 的 Loaders** 内的输入输出、预估耗时、参数等数据分析的功能。
40
40
 
41
41
  <img
42
42
  src="https://assets.rspack.dev/others/assets/rsdoctor/loader-timeline-overall.png"
@@ -75,40 +75,70 @@ export default {
75
75
  - **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
76
76
 
77
77
  :::tip
78
- 对于使用 Modern.js Webpack 模式的项目,请使用 [tools.webpack](https://modernjs.dev/configure/app/tools/webpack) 注册 `RsdoctorWebpackPlugin` 插件。
78
+ 对于使用 Modern.js webpack 模式的项目,请使用 [tools.webpack](https://modernjs.dev/configure/app/tools/webpack) 注册 `RsdoctorWebpackPlugin` 插件。
79
79
  :::
80
80
 
81
81
  ### Next.js 项目
82
82
 
83
83
  在 `next.config.js` 的 [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) 中初始化 RsdoctorWebpackPlugin 插件。
84
84
 
85
- ```ts title="next.config.mjs"
85
+ ```ts title="next.config.ts"
86
+ import type { NextConfig } from 'next';
86
87
  import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
87
88
 
88
- export default {
89
- // ...
90
- webpack: (config, { isServer }) => {
91
- config.plugins.push(
92
- new RsdoctorWebpackPlugin({
93
- // 插件选项
94
- }),
95
- );
89
+ const nextConfig: NextConfig = {
90
+ /* config options here */
91
+ webpack: (config) => {
92
+ if (config.name === 'client') {
93
+ config.plugins.push(
94
+ new RsdoctorWebpackPlugin({
95
+ disableClientServer: true,
96
+ }),
97
+ );
98
+ } else if (config.name === 'server') {
99
+ config.plugins.push(
100
+ new RsdoctorWebpackPlugin({
101
+ disableClientServer: true,
102
+ output: {
103
+ reportDir: './.next/server',
104
+ },
105
+ }),
106
+ );
107
+ }
96
108
  return config;
97
109
  },
98
110
  };
111
+
112
+ export default nextConfig;
99
113
  ```
100
114
 
101
115
  - **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
102
116
 
103
117
  #### 📢 Next.js 项目使用注意
104
118
 
105
- 1. Next.js 项目报告页面问题
119
+ 由于 Next.js 在 `build` 执行结束后会终止终端服务,因此 Rsdoctor 在构建过程中运行的报告页面服务器也会被关闭。此时,你可以通过 [@rsdoctor/cli](/guide/start/cli) 再次打开页面报告,而无需重新执行构建操作。
120
+
121
+ - 首先,安装 [@rsdoctor/cli](/guide/start/cli):
106
122
 
107
- 详情查看:[FAQ](../more/faq#nextjs)
123
+ import { PackageManagerTabs } from '@theme';
108
124
 
109
- 2. Next.js 中不支持对 rules 进行重写的 Loader 分析
125
+ <PackageManagerTabs command="add @rsdoctor/cli -D" />
110
126
 
111
- 详情查看:[FAQ](../more/faq#nextjs)
127
+ - 其次,**package.json** 里添加如下 scripts 命令,执行 **client:rsdoctor** 或者 **server:rsdoctor** 可打开对应构建器的报告:
128
+
129
+ ```ts
130
+ "scripts": {
131
+ "client:rsdoctor": "rsdoctor analyze --profile .next/.rsdoctor/manifest.json",
132
+ "server:rsdoctor": "rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json"
133
+ }
134
+ ```
135
+
136
+ 例如:Rsdoctor 的构建产物在 `.next/server/chunks/.rsdoctor/manifest.json` 路径,则可通过执行下面命令来打开报告页面:
137
+
138
+ ```bash
139
+ rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json
140
+
141
+ ```
112
142
 
113
143
  ### Vue 项目
114
144
 
@@ -135,7 +135,8 @@
135
135
  开启 BannerPlugin 分析时,请勿在生产版本中使用 Rsdoctor。
136
136
  :::
137
137
 
138
- 由于 Rspack 和 Webpack 都支持 [BannerPlugin](https://www.rspack.dev/plugins/webpack/banner-plugin#bannerplugin),BannerPlugin 是可在生成的 chunk 顶部或尾部添加一段指定的内容的内置插件。
138
+ 由于 Rspack 和 webpack 都支持 [BannerPlugin](https://www.rspack.dev/plugins/webpack/banner-plugin#bannerplugin),BannerPlugin 是可在生成的 chunk 顶部或尾部添加一段指定的内容的内置插件。
139
+
139
140
  添加的代码段将会影响到对 Bundle 的解析能力。
140
141
 
141
142
  Rsdoctor 兼容了对 BannerPlugin 这种添加代码的逻辑,但因为 Rsdoctor 需要添加标记代码,所以没有默认开启,以下两种情况会开启 Rsdoctor BannerPlugin 能力:
@@ -27,7 +27,7 @@
27
27
 
28
28
  ### 名词解释
29
29
 
30
- - **`Reasons`** : 顾名思义是 `[原因]` 的意思,即某个 `Module` 存在的原因。Reasons 就是该 `Module` 被哪些 `Module` 们引入,而整个 `Reasons Tree` 就是这个 `Module` 的整个上游引用链,包括了直接父级和间接父级们。[即 Webpack 的 stats.reasons。](https://webpack.js.org/configuration/stats/#statsreasons)
30
+ - **`Reasons`** : 顾名思义是 `[原因]` 的意思,即某个 `Module` 存在的原因。Reasons 就是该 `Module` 被哪些 `Module` 们引入,而整个 `Reasons Tree` 就是这个 `Module` 的整个上游引用链,包括了直接父级和间接父级们。[即 Rspack 的 stats.reasons。](https://webpack.js.org/configuration/stats/#statsreasons)
31
31
  - **`Dependencies`** : 是该 `Module` 依赖了哪些 `Module`。
32
32
 
33
33
  ## Reasons 依赖树
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 功能概览
4
4
 
5
- 我们在 **Rsdoctor** 内 `Compile Analysis` 的二级页面 `Plugins Analysis` 中,可以看到当前 Rspack 或 Webpack 项目中所有被插件使用过的 **Compiler Hooks** 以及 **Compilation Hooks** 的调用数据信息,其内容如下图所示:
5
+ 我们在 **Rsdoctor** 内 `Compile Analysis` 的二级页面 `Plugins Analysis` 中,可以看到当前 Rspack 或 webpack 项目中所有被插件使用过的 **Compiler Hooks** 以及 **Compilation Hooks** 的调用数据信息,其内容如下图所示:
6
6
 
7
7
  <img
8
8
  src="https://assets.rspack.dev/others/assets/rsdoctor/plugins-analysis-overall.png"
@@ -29,7 +29,7 @@ plugin 耗时中会计算 Rsdoctor 的内部插件耗时。
29
29
 
30
30
  ### View bundler config
31
31
 
32
- 如果我们需要查看项目的 Rspack 或 Webpack 配置,则可以通过点击卡片右上角的 `View Bundler Config`,页面会弹出一个浮层,其中包含被序列化后的 **Bundler Config**,如下图所示:
32
+ 如果我们需要查看项目的 Rspack 或 webpack 配置,则可以通过点击卡片右上角的 `View Bundler Config`,页面会弹出一个浮层,其中包含被序列化后的 **Bundler Config**,如下图所示:
33
33
 
34
34
  <img
35
35
  src="https://assets.rspack.dev/others/assets/rsdoctor/plugins-analysis-config.png"
@@ -6,31 +6,29 @@
6
6
 
7
7
  <img
8
8
  src="https://assets.rspack.dev/others/assets/rsdoctor/project-overall-1.jpg"
9
- width="400px"
10
- height="600px"
11
9
  style={{ margin: 'auto' }}
12
10
  />
13
11
 
14
12
  ## 名词释义
15
13
 
16
- | 名词 | 描述说明 |
17
- | --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
18
- | <b><i>errors</i></b> | 代表 Rsdoctor 在当次运行中检测出的 **error** 级别的规则 |
19
- | <b><i>warns</i></b> | 代表 Rsdoctor 在当次运行中检测出的 **warn** 级别的规则 |
20
- | <b><i>webpack</i></b> | 代表当次运行时获取到的 Webpack 版本 |
21
- | <b><i>cwd</i></b> | 代表当次运行时的进程执行目录,即 [process.cwd()](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processcwd) |
22
- | <b><i>cpu</i></b> | 代表 cpu 信息 |
23
- | <b><i>memory</i></b> | 代表当次运行时的 memory 信息 |
24
- | <b><i>node</i></b> | 代表 [Node.js](https://nodejs.org/) 版本号 |
25
- | <b><i>yarn</i></b> | 代表 [Yarn](https://yarnpkg.com/) 版本号,如果没有找到则显示为 `Not Found` |
26
- | <b><i>npm</i></b> | 代表 [npm](https://www.npmjs.com/) 版本号 |
27
- | <b><i>pnpm</i></b> | 代表 [pnpm](https://pnpm.io/) 版本号,如果没有找到则显示为 `Not Found` |
14
+ | 名词 | 描述说明 |
15
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------- |
16
+ | <b><i>errors</i></b> | 代表 Rsdoctor 在当次运行中检测出的 **error** 级别的规则 |
17
+ | <b><i>warns</i></b> | 代表 Rsdoctor 在当次运行中检测出的 **warn** 级别的规则 |
18
+ | <b><i>rspack</i></b> | 代表当次运行时获取到的 Rspack 版本 |
19
+ | <b><i>cwd</i></b> | 代表当次运行时的进程执行目录,即 [process.cwd()](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processcwd) |
20
+ | <b><i>cpu</i></b> | 代表 cpu 信息 |
21
+ | <b><i>memory</i></b> | 代表当次运行时的 memory 信息 |
22
+ | <b><i>node</i></b> | 代表 [Node.js](https://nodejs.org/) 版本号 |
23
+ | <b><i>yarn</i></b> | 代表 [Yarn](https://yarnpkg.com/) 版本号,如果没有找到则显示为 `Not Found` |
24
+ | <b><i>npm</i></b> | 代表 [npm](https://www.npmjs.com/) 版本号 |
25
+ | <b><i>pnpm</i></b> | 代表 [pnpm](https://pnpm.io/) 版本号,如果没有找到则显示为 `Not Found` |
28
26
 
29
27
  ## 使用说明
30
28
 
31
29
  ### View bundler config
32
30
 
33
- 如果我们需要查看项目的 Rspack 或 Webpack 配置,则可以通过点击卡片右上角的 `View Bundler Config`,页面会弹出一个浮层,其中包含被序列化后的 [Bundler Config](https://webpack.js.org/configuration/),如下图所示:
31
+ 如果我们需要查看项目的 Rspack 或 webpack 配置,则可以通过点击卡片右上角的 `View Bundler Config`,页面会弹出一个浮层,其中包含被序列化后的 [Bundler Config](https://webpack.js.org/configuration/),如下图所示:
34
32
 
35
33
  <img
36
34
  src="https://assets.rspack.dev/others/assets/rsdoctor/project-overall-config.jpg"
@@ -17,7 +17,7 @@ new rsdoctorRspackPlugin({
17
17
 
18
18
  :::
19
19
 
20
- 我们在 **Rsdoctor** 内 `Module Resolve` 中,可以看到当前 Webpack 项目中的所有源文件,通过**点击某个文件**可以查看该文件中引入的**模块路径**、**解析前后的路径对比**、**解析耗时**等信息,其内容如下图所示:
20
+ 我们在 **Rsdoctor** 内 `Module Resolve` 中,可以看到当前 Rspack 项目中的所有源文件,通过**点击某个文件**可以查看该文件中引入的**模块路径**、**解析前后的路径对比**、**解析耗时**等信息,其内容如下图所示:
21
21
 
22
22
  <img src="https://assets.rspack.dev/others/assets/rsdoctor/resolver.png" />
23
23
 
@@ -1,6 +1,6 @@
1
1
  # 编译诊断规则
2
2
 
3
- 构建诊断规则是类似于 `ESLint` 的 lint 工具,但是与其不同之处在于,`ESLint` 是在静态情况下进行代码扫描和构建流程无关。而这里的代码诊断是和 `Rspack 或 Webpack` 的构建流程紧密相关的,其中会加入许许多多构建中产生的内部参数用于辅助判断,比如 ModuleGraph,比如 Webpack 对每个模块的内部标记,比如代码经过转换之后加入的 runtime 等等……
3
+ 构建诊断规则是类似于 `ESLint` 的 lint 工具,但是与其不同之处在于,`ESLint` 是在静态情况下进行代码扫描和构建流程无关。而这里的代码诊断是和 `Rspack 或 Webpack` 的构建流程紧密相关的,其中会加入许许多多构建中产生的内部参数用于辅助判断,比如 ModuleGraph,比如 Rspack 对每个模块的内部标记,比如代码经过转换之后加入的 runtime 等等……
4
4
 
5
5
  在构建过程中发现了问题,会在 CLI 和最后弹出的诊断汇总网页中看到,如下图:
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/docs",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -19,7 +19,7 @@
19
19
  "registry": "https://registry.npmjs.org/"
20
20
  },
21
21
  "devDependencies": {
22
- "@rspress/plugin-rss": "1.41.3",
22
+ "@rspress/plugin-rss": "2.0.0-alpha.3",
23
23
  "@types/node": "^16",
24
24
  "@types/react": "^18.3.18",
25
25
  "@types/react-dom": "^18.3.5",
@@ -30,12 +30,12 @@
30
30
  "rspress-plugin-font-open-sans": "^1.0.0",
31
31
  "rspress-plugin-sitemap": "^1.1.1",
32
32
  "typescript": "^5.2.2",
33
- "@rsdoctor/types": "1.0.0-rc.0"
33
+ "@rsdoctor/types": "1.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@rstack-dev/doc-ui": "1.7.2",
36
+ "@rstack-dev/doc-ui": "1.7.3",
37
37
  "react-markdown": "^9.0.3",
38
- "rspress": "1.41.3"
38
+ "rspress": "2.0.0-alpha.3"
39
39
  },
40
40
  "scripts": {
41
41
  "dev": "rspress dev",
Binary file