@rsdoctor/docs 1.0.0-beta.3 → 1.0.0-rc.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rsdoctor Website
1
+ # Rsdoctor website
2
2
 
3
3
  ## Writing style guide
4
4
 
@@ -1,6 +1,6 @@
1
1
  # Duplicate dependency problem
2
2
 
3
- Rsdoctor will report cases where multiple duplicate dependencies exist in the same builder's artifact.
3
+ Rsdoctor will report cases where multiple duplicate dependencies exist in the same bundler's artifact.
4
4
 
5
5
  <img src="https://assets.rspack.dev/others/assets/rsdoctor/bundle-alerts.png" />
6
6
 
@@ -8,7 +8,7 @@ Rsdoctor will report cases where multiple duplicate dependencies exist in the sa
8
8
 
9
9
  - **Security**
10
10
  - Many packages adopt singleton mode and are only loaded once by default. Examples include core-js, react, and some component libraries. Having multiple versions coexist can cause runtime errors.
11
- - **Runtime Perßformance**
11
+ - **Runtime Performance**
12
12
  - Increases artifact size, slowing down network transmission
13
13
  - Same code for the same functionality runs multiple times
14
14
 
@@ -38,10 +38,9 @@ However, before using them, it is important to consider the compatibility betwee
38
38
 
39
39
  #### Use [resolve.alias](https://www.rspack.dev/config/resolve.html#resolvealias)
40
40
 
41
- Almost all builders support modifying the paths for resolving npm packages. Therefore, we can eliminate duplicate dependencies by manually specifying the resolve paths for packages during compilation. For example, using **Rspack** or **Webpack**, if `lodash` is duplicated in the build, we can configure it as follows to specify the resolve paths for all `lodash` packages to the `node_modules` directory in the current directory.
41
+ Almost all bundlers support customizing the resolution paths for npm packages. Therefore, we can eliminate duplicate dependencies by manually specifying the resolve paths for packages during compilation. For example, using **Rspack** or **Webpack**, if `lodash` is duplicated in the build, we can configure it as follows to specify the resolve paths for all `lodash` packages to the `node_modules` directory in the current directory.
42
42
 
43
- ```js
44
- // webpack.config.js/rspack.config.js
43
+ ```js title="rspack.config.js"
45
44
  const path = require('path');
46
45
 
47
46
  module.exports = {
@@ -71,7 +70,7 @@ In this project, the `web` app depends on `react@18.2.0` and imports `component`
71
70
  │ │ └── react -> ../../../node_modules/.pnpm/react@18.2.0
72
71
  │ ├── src
73
72
  │ │ └── index.js
74
- │ ├── webpack.config.js
73
+ │ ├── rspack.config.js
75
74
  │ └── package.json
76
75
  └── packages
77
76
  └── component
@@ -82,14 +81,14 @@ In this project, the `web` app depends on `react@18.2.0` and imports `component`
82
81
  └── package.json
83
82
  ```
84
83
 
85
- When executing `webpack build` under `apps/web`, the code in the `web` directory will be resolved to `react@18.2.0`, and then the code in the `component` directory will be resolved to `react@18.1.0`. This results in the output of the web project containing two versions of `React`.
84
+ When executing `rspack build` under `apps/web`, the code in the `web` directory will be resolved to `react@18.2.0`, and then the code in the `component` directory will be resolved to `react@18.1.0`. This results in the output of the web project containing two versions of `React`.
86
85
 
87
86
  #### Solution
88
87
 
89
- This issue can be resolved using the `resolve.alias` configuration in the builder, such as `Rspack` or `Webpack`. By specifying the resolve path for `React` to only resolve to `apps/web/node_modules/react`, you can ensure that only one version of `React` is included in the output. Here is an example code:
88
+ This issue can be resolved using the `resolve.alias` configuration of the bundler, such as Rspack or webpack. By specifying the resolve path for `React` to only resolve to `apps/web/node_modules/react`, you can ensure that only one version of `React` is included in the output. Here is an example code:
90
89
 
91
90
  ```javascript
92
- // apps/web/webpack.config.js
91
+ // apps/web/rspack.config.js
93
92
  const path = require('path');
94
93
 
95
94
  module.exports = {
@@ -116,7 +115,7 @@ This handling method also applies to projects with duplicate packages caused by
116
115
  │ │ └── debug -> ../../../node_modules/.pnpm/debug@4.3.4
117
116
  │ ├── src
118
117
  │ │ └── index.js
119
- │ ├── webpack.config.js
118
+ │ ├── rspack.config.js
120
119
  │ └── package.json
121
120
  └── packages
122
121
  └── component
@@ -127,14 +126,14 @@ This handling method also applies to projects with duplicate packages caused by
127
126
  └── package.json
128
127
  ```
129
128
 
130
- In this project, when executing `webpack build` under `apps/web`, the code in the `web` directory will be resolved to `axios@0.27.2_debug@4.3.4`, and then the code in the `packages/component` directory will be resolved to `axios@0.27.2`.
129
+ In this project, when executing `rspack build` under `apps/web`, the code in the `web` directory will be resolved to `axios@0.27.2_debug@4.3.4`, and then the code in the `packages/component` directory will be resolved to `axios@0.27.2`.
131
130
 
132
131
  Although they are the same version, they have different paths, resulting in two copies of `axios` in the output.
133
132
 
134
133
  The solution is to configure the `web` project to only resolve the `axios` package under the `web` directory's `node_modules`.
135
134
 
136
135
  ```javascript
137
- // apps/web/webpack.config.js
136
+ // apps/web/rspack.config.js
138
137
  alias: {
139
138
  'axios': path.resolve(__dirname, 'node_modules/axios')
140
139
  }
@@ -15,7 +15,7 @@ new RsdoctorRspackPlugin({
15
15
  ## Loader time-consuming data is inaccurate?
16
16
 
17
17
  The time-consuming data provided by Rsdoctor for loaders is an **estimated time**. Why can't it accurately measure the timing? It's because we know that loader execution can be both **asynchronous** and **synchronous**.
18
- Additionally, the builder will **parallelize the execution** of multiple non-conflicting loader functions. Since JavaScript is single-threaded, multiple loader functions can **compete for the current task queue**.
18
+ Additionally, the bundler will **parallelize the execution** of multiple non-conflicting loader functions. Since JavaScript is single-threaded, multiple loader functions can **compete for the current task queue**.
19
19
  Furthermore, the asynchronous logic within loader functions cannot be recognized, causing a single loader function to potentially span across the execution of multiple other loaders. As a result, there are three possible cases, as shown in the following diagram:
20
20
 
21
21
  <img
@@ -8,9 +8,9 @@ Please refer to the [Linter Type](#linter-type) in this document for the type de
8
8
 
9
9
  :::
10
10
 
11
- ### [E1001] Duplicate Packages
11
+ ### [E1001] Duplicate packages
12
12
 
13
- #### Rule Details
13
+ #### Rule details
14
14
 
15
15
  - The `Duplicate Packages` card displays the number of duplicate third-party packages in the project. Clicking the image allows you to view the specific details of the duplicate third-party packages. Note: The third-party packages referred to here are all bundled third-party packages.
16
16
 
@@ -91,13 +91,13 @@ enum CheckVersion {
91
91
  }
92
92
  ```
93
93
 
94
- #### Duplicate Package Optimization Problem
94
+ #### Duplicate package optimization problem
95
95
 
96
96
  Please refer to the [Duplicate Package Optimization Solution](../../blog/topic/duplicate-pkg-problem).
97
97
 
98
98
  Clicking 「**More**」 can view the corresponding rule explanation.
99
99
 
100
- ### [E1002] Cross Chunks Package
100
+ ### [E1002] Cross chunks package
101
101
 
102
102
  The cross chunks duplicate package rule can scan **duplicate packages in different `chunks`**. These duplicate packages may also lead to redundant code in the build artifacts, depending on the business logic and the size of the redundant code.
103
103
 
@@ -111,7 +111,7 @@ The cross chunks duplicate package rule can scan **duplicate packages in differe
111
111
 
112
112
  Please refer to [[E1002] Cross Chunks Packages](../more/rules)
113
113
 
114
- ### [E1003] Loader Performance Optimization
114
+ ### [E1003] Loader performance optimization
115
115
 
116
116
  This module allows you to visually see some warning information about our project's compilation, which can help us further optimize the project's compilation performance.
117
117
 
@@ -119,7 +119,7 @@ This module allows you to visually see some warning information about our projec
119
119
 
120
120
  Please refer to [[E1003] Loader Performance Optimization](../more/rules)
121
121
 
122
- #### Configuration Type
122
+ #### Configuration type
123
123
 
124
124
  - **ignore**: Can include strings or regular expressions, used to specify the loaders to be ignored.
125
125
  - **threshold**: Represents the total time threshold for the loader, in milliseconds. If the loader's execution time exceeds this threshold, it may trigger warnings or errors. The default value is 5000 milliseconds.
@@ -145,7 +145,7 @@ interface Config {
145
145
  }
146
146
  ```
147
147
 
148
- ### [E1004] ECMA Version Check
148
+ ### [E1004] ECMA version check
149
149
 
150
150
  This rule is used to detect incompatible advanced syntax. When scanning the rule, the configuration of `browserslist` is prioritized; if `browserslist` is not configured, manual detection is required, as shown below:
151
151
 
@@ -171,7 +171,7 @@ export default {
171
171
  };
172
172
  ```
173
173
 
174
- #### Type Definitions
174
+ #### Type definitions
175
175
 
176
176
  ```ts
177
177
  type CheckSyntaxOptions = {
@@ -205,7 +205,7 @@ type CheckSyntaxOptions = {
205
205
 
206
206
  For more `ECMA Version Check` configuration options, please refer to [ECMA Version Check Options](https://github.com/rspack-contrib/rsbuild-plugin-check-syntax?tab=readme-ov-file#options)
207
207
 
208
- ### [E1005] Default Import Check
208
+ ### [E1005] Default import check
209
209
 
210
210
  Typically, Rspack automatically supports different types of modules, but in some cases, compatibility operations may fail. For example, when using `Default Import` to import a `cjs` module, if the module does not have a compatible statement (such as `exports.default`), issues may arise.
211
211
 
@@ -224,7 +224,7 @@ interface Config {
224
224
  }
225
225
  ```
226
226
 
227
- ## Linter Type
227
+ ## Linter type
228
228
 
229
229
  - The type definition for the `linter` field is as follows:
230
230
 
@@ -96,7 +96,7 @@ import { execute } from '@rsdoctor/cli';
96
96
 
97
97
  **execute()**
98
98
 
99
- The `execute` asynchronous function is the execution function of Rsdoctor CLI. By calling the `execute` function, it will automatically parse [process.argv](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processargv) and invoke different commands.
99
+ The `execute` asynchronous function is the execution function of Rsdoctor CLI. By calling the `execute` function, it will automatically parse [process.argv](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processargv) and invoke different commands.
100
100
 
101
101
  **execute('analyze', \{...\})**
102
102
 
@@ -1,4 +1,4 @@
1
- ## Step 2: Register plugin
1
+ ## Step 2: register plugin
2
2
 
3
3
  After the dependency installation, you need to integrate the Rsdoctor plugin into your project. Below are some examples of common tools and frameworks:
4
4
 
@@ -141,7 +141,7 @@ export default defineConfig({
141
141
 
142
142
  ---
143
143
 
144
- ## Step 3: Run build
144
+ ## Step 3: run build
145
145
 
146
146
  Now, you can run the **build** command in the project. After the build is complete, Rsdoctor will automatically open the analysis page of this build.
147
147
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  This document will explain how to access the Rsdoctor ability.
4
4
 
5
- ## Step 1: Install dependencies
5
+ ## Step 1: install dependencies
6
6
 
7
7
  import { PackageManagerTabs } from '@theme';
8
8
 
@@ -15,10 +15,10 @@ For projects based on Rspack or Rsbuild, install the following dependencies:
15
15
  ### Webpack projects
16
16
 
17
17
  :::tip
18
- Not supported in Webpack 4.
18
+ Rsdoctor only supports webpack >= 5.
19
19
  :::
20
20
 
21
- For projects based on Webpack, install the following dependencies:
21
+ For projects based on webpack, install the following dependencies:
22
22
 
23
23
  <PackageManagerTabs command="add @rsdoctor/webpack-plugin -D" />
24
24
 
@@ -1,4 +1,4 @@
1
- # Bundle Alerts
1
+ # Bundle alerts
2
2
 
3
3
  ## Introduction
4
4
 
@@ -19,7 +19,7 @@ Click on the **"Bundle Size"** option in the navigation bar to view the Bundle a
19
19
 
20
20
  - **`Assets`**: Resources refer to images, fonts, media, and other file types. They are the files that ultimately exist in the output folder. Each Chunk has corresponding [Assets resources](https://webpack.js.org/concepts/under-the-hood/#chunks).
21
21
  - **`Module`**: One or more Modules combine to form a Chunk. For more information about Module types, please refer to [Rspack Modules](https://www.rspack.dev/api/modules.html) and [Webpack Modules](https://webpack.js.org/concepts/modules/#what-is-a-webpack-module).
22
- - **`Bundle Size`**: The final packaged size of the resource artifact, which is the final size after being processed by the builder.
22
+ - **`Bundle Size`**: The final packaged size of the resource artifact, which is the final size after being processed by the bundler.
23
23
  - **`Module Bundled Source & Size`**: **Module Parsed Source** refers to the final code fragment of the **Module** in the packaged artifact, and **Module Parsed Size** refers to the size of the final code fragment of the **Module** in the packaged artifact.
24
24
  - **`Package Count`**: The number of third-party packages.
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".
@@ -82,7 +82,7 @@ The top toolbar from left to right includes: the search tool for **Assets**, the
82
82
 
83
83
  <img src="https://assets.rspack.dev/others/assets/rsdoctor/bundle-size-analysis-selects.png" />
84
84
 
85
- #### Search Module
85
+ #### Search module
86
86
 
87
87
  Search for which Assets the Module is located in. As shown in the figure, you can see the results of matching the search Module keyword.
88
88
 
@@ -91,7 +91,7 @@ Search for which Assets the Module is located in. As shown in the figure, you ca
91
91
  src="https://assets.rspack.dev/others/assets/rsdoctor/search-modules.png"
92
92
  />
93
93
 
94
- #### Search Module
94
+ #### Search module
95
95
 
96
96
  The module search functionality is supported, allowing users to click the "**Search Module**" button to open the module search dialog. By entering the module name, users can quickly locate and view the module's position in the Assets, making it easier to analyze the module's reference relationships and size. The search determines which Assets the Module is located in.
97
97
 
@@ -149,17 +149,16 @@ The added code segment will affect the analysis capability of the bundle.
149
149
 
150
150
  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:
151
151
 
152
- 1. The project uses the BannerPlugin in `rspack.config.j|ts` or `webpack.config.j|ts`.
152
+ 1. The project uses the BannerPlugin in `rspack.config.(js|ts)` or `webpack.config.(js|ts)`.
153
153
 
154
154
  2. Enable Rsdoctor BannerPlugin capability through Rsdoctor options by setting `supports.banner`:
155
155
 
156
156
  ```ts
157
- new RsdoctorRspackPlugin (
157
+ new RsdoctorRspackPlugin({
158
158
  supports: {
159
- banner: true
160
- }
161
- )
162
-
159
+ banner: true,
160
+ },
161
+ });
163
162
  ```
164
163
 
165
164
  - Note: Enabling `drop_console` will affect Rsdoctor's analysis of the BannerPlugin. Therefore, you can disable `drop_console` when `RSDOCTOR = true`.
@@ -1,4 +1,4 @@
1
- # Compile Alerts
1
+ # Compile alerts
2
2
 
3
3
  We have integrated some capabilities based on compilation data detection. If the current compilation result contains data that hits the rules we define, the `Compile Alerts` module will appear at the bottom of the **Rsdoctor** main interface, as shown in the image below:
4
4
 
@@ -19,12 +19,12 @@ For each compilation phase, if the time data is displayed in <u>blue</u>, it mea
19
19
 
20
20
  The following table explains the meaning and code implementation of each phase in the card:
21
21
 
22
- | Phase Name | Description | Code Implementation |
23
- | ---------------------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
- | <b><i>Bootstrap -> BeforeCompile</i></b> | Represents the time taken from project startup to before compilation starts | <ul><li>In `Webpack` or `Rspack` projects: Reports [process.uptime()](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processuptime) as the <b>duration</b> when **compiler.hooks.beforeCompile** is called</li></ul> |
25
- | <b><i>Compile</i></b> | Represents the total time taken for the project compilation | <ul><li>In `Webpack` or `Rspack` projects: The <b>start time</b> is the time when **compiler.hooks.beforeCompile** is called, and the <b>end time</b> is the time when **compiler.hooks.afterCompile** is called</li></ul> |
26
- | <b><i>AfterCompile -> Done</i></b> | Represents the time taken from compilation completion to the end of the entire process | <ul><li>In `Webpack` or `Rspack` projects: The <b>start time</b> is the time when **compiler.hooks.afterCompile** is called, and the <b>end time</b> is the time when **compiler.hooks.done** is called</li></ul> |
27
- | <b><i>Minify</i></b> | Represents the time taken for file compression during the compilation process in most cases | <ul><li>In `Webpack` or `Rspack` projects: Calculates the sum of the time taken for each call of **compilation.hooks.optimizeChunkAssets** and **compilation.hooks.processAssets**</li></ul> |
22
+ | Phase Name | Description | Code Implementation |
23
+ | ---------------------------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | <b><i>Bootstrap -> BeforeCompile</i></b> | Represents the time taken from project startup to before compilation starts | <ul><li>Reports [process.uptime()](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processuptime) as the <b>duration</b> when **compiler.hooks.beforeCompile** is called</li></ul> |
25
+ | <b><i>Compile</i></b> | Represents the total time taken for the project compilation | <ul><li>The <b>start time</b> is the time when **compiler.hooks.beforeCompile** is called, and the <b>end time</b> is the time when **compiler.hooks.afterCompile** is called</li></ul> |
26
+ | <b><i>AfterCompile -> Done</i></b> | Represents the time taken from compilation completion to the end of the entire process | <ul><li>The <b>start time</b> is the time when **compiler.hooks.afterCompile** is called, and the <b>end time</b> is the time when **compiler.hooks.done** is called</li></ul> |
27
+ | <b><i>Minify</i></b> | Represents the time taken for file compression during the compilation process in most cases | <ul><li>Calculates the sum of the time taken for each call of **compilation.hooks.optimizeChunkAssets** and **compilation.hooks.processAssets**</li></ul> |
28
28
 
29
29
  ## Usage instructions
30
30
 
@@ -56,7 +56,7 @@ Hovering over a data point in the chart will display the following information i
56
56
 
57
57
  In this section, you can navigate to "Compile Analysis" -> "Loader Analysis" -> [**"Loader Timeline"**](./loaders-timeline.mdx) in the navigation bar to view the timeline of loader compilation time.
58
58
 
59
- ### AfterCompile -> Done details
59
+ ### AfterCompile -> done details
60
60
 
61
61
  By **clicking on the data of the `AfterCompile -> Done` phase**, a popup will appear on the page, as shown in the following image:
62
62
 
@@ -18,7 +18,7 @@ In the main page of **Rsdoctor**, we can see a card named `Project Overall`, whi
18
18
  | <b><i>errors</i></b> | Represents the **error** level rules detected by Rsdoctor during the current run |
19
19
  | <b><i>warns</i></b> | Represents the **warn** level rules detected by Rsdoctor during the current run |
20
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-v18.x/docs/api/process.html#processcwd) |
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
22
  | <b><i>cpu</i></b> | Represents the CPU information |
23
23
  | <b><i>memory</i></b> | Represents the memory information during the current run |
24
24
  | <b><i>node</i></b> | Represents the version number of [Node.js](https://nodejs.org/) |
@@ -1,4 +1,4 @@
1
- # Compilation Diagnostic Rules
1
+ # Compilation diagnostic rules
2
2
 
3
3
  Building diagnostic rules is similar to `ESLint` like lint tools, but different from it in that `ESLint` performs code scanning and is unrelated to the build process. In contrast, the code diagnostics here are closely related to the build process of `Rspack or Webpack`, incorporating many internal parameters generated during the build process to aid judgment, such as ModuleGraph, Webpack's internal markings for each module, and runtime added after code transformation, among others.
4
4
 
@@ -16,7 +16,7 @@ During the build process, if issues are discovered, they will be visible in the
16
16
  src="https://assets.rspack.dev/others/assets/rsdoctor/bundle-alerts.png"
17
17
  />
18
18
 
19
- ## How to Use
19
+ ## How to use
20
20
 
21
21
  Currently, Rsdoctor provides **built-in rules** and **custom rules**.
22
22
 
@@ -32,6 +32,6 @@ The existing diagnostic tool includes multiple rules, all of which are enabled b
32
32
 
33
33
  For specific details, refer to [Built-in Rules](/guide/rules/rules).
34
34
 
35
- ### Custom Rules
35
+ ### Custom rules
36
36
 
37
37
  Rsdoctor also collects analyzed data and allows users to integrate custom rules through the Linter API. For details on custom rules, refer to [Custom Rules](/guide/rules/rule-custom).
@@ -37,10 +37,9 @@ Rsdoctor 会在产物预警中报告对同一份产物中含有多个重复依
37
37
 
38
38
  #### 使用 [resolve.alias](https://www.rspack.dev/config/resolve.html#resolvealias)
39
39
 
40
- 基本所有的构建器都支持对 npm 包解析的路径进行修改。因此我们可以通过在编译时手动指定 package 的 resolve 路径,来达到消除重复依赖的目的,例如:以 **Rspack** 或 **Webpack** 为例,如果 `lodash` 重复打包,我们可以进行如下配置,将所有 `lodash` 的 resolve 路径指定到当前目录的 `node_modules` 中。
40
+ 几乎所有的打包工具都提供了自定义 npm 包解析路径的功能。因此我们可以通过在编译时手动指定 package 的 resolve 路径,来达到消除重复依赖的目的,例如:以 **Rspack** 或 **Webpack** 为例,如果 `lodash` 重复打包,我们可以进行如下配置,将所有 `lodash` 的 resolve 路径指定到当前目录的 `node_modules` 中。
41
41
 
42
- ```js
43
- // webpack.config.js/rspack.config.js
42
+ ```js title="rspack.config.js"
44
43
  const path = require('path');
45
44
 
46
45
  module.exports = {
@@ -70,7 +69,7 @@ module.exports = {
70
69
  │ │ └── react -> ../../../node_modules/.pnpm/react@18.2.0
71
70
  │ ├── src
72
71
  │ │ └── index.js
73
- │ ├── webpack.config.js
72
+ │ ├── rspack.config.js
74
73
  │ └── package.json
75
74
  └── packages
76
75
  └── component
@@ -81,14 +80,14 @@ module.exports = {
81
80
  └── package.json
82
81
  ```
83
82
 
84
- 在 `apps/web` 下执行 `webpack build`,打包 web 下的代码时,会解析到 `react@18.2.0`,接着打包 `component` 下的代码时,会解析到 `react@18.1.0`,这导致 web 项目的产物中同时含有两个版本的 `React`。
83
+ 在 `apps/web` 下执行 `rspack build`,打包 web 下的代码时,会解析到 `react@18.2.0`,接着打包 `component` 下的代码时,会解析到 `react@18.1.0`,这导致 web 项目的产物中同时含有两个版本的 `React`。
85
84
 
86
85
  #### 解决方案
87
86
 
88
- 此问题可以通过构建器的 [resolve.alias](https://www.rspack.dev/config/resolve.html#resolvealias) 来解决。让 `Rspack``Webpack` 解析 `React` 时只解析到 `apps/web/node_modules/react` 这一个版本,示例代码如下:
87
+ 此问题可以通过打包工具的 [resolve.alias](https://www.rspack.dev/config/resolve.html#resolvealias) 来解决。让 Rspack 或 webpack 解析 `React` 时只解析到 `apps/web/node_modules/react` 这一个版本,示例代码如下:
89
88
 
90
89
  ```javascript
91
- // apps/web/webpack.config.js
90
+ // apps/web/rspack.config.js
92
91
  const path = require('path');
93
92
 
94
93
  module.exports = {
@@ -115,7 +114,7 @@ module.exports = {
115
114
  │ │ └── debug -> ../../../node_modules/.pnpm/debug@4.3.4
116
115
  │ ├── src
117
116
  │ │ └── index.js
118
- │ ├── webpack.config.js
117
+ │ ├── rspack.config.js
119
118
  │ └── package.json
120
119
  └── packages
121
120
  └── component
@@ -126,12 +125,12 @@ module.exports = {
126
125
  └── package.json
127
126
  ```
128
127
 
129
- 在该项目中,在 `apps/web` 下执行 `webpack build`,打包 web 下的代码时,会解析到 `axios@0.27.2_debug@4.3.4`,接着打包 `packages/component` 下的代码时,会解析到 `axios@0.27.2`,它们虽然是同一版本,但路径不同,产物中也会存在两份 `axios`。
128
+ 在该项目中,在 `apps/web` 下执行 `rspack build`,打包 web 下的代码时,会解析到 `axios@0.27.2_debug@4.3.4`,接着打包 `packages/component` 下的代码时,会解析到 `axios@0.27.2`,它们虽然是同一版本,但路径不同,产物中也会存在两份 `axios`。
130
129
 
131
130
  解决方案如下,让 `web` 项目构建时都只解析到 `web` 下 `node_modules` 的 `axios` 包即可。
132
131
 
133
132
  ```javascript
134
- // apps/web/webpack.config.js
133
+ // apps/web/rspack.config.js
135
134
  alias: {
136
135
  'axios': path.resolve(__dirname, 'node_modules/axios')
137
136
  }
@@ -87,9 +87,9 @@ new RsdoctorWebpackPlugin({
87
87
 
88
88
  <Badge text="Version: 0.4.0" type="warning" />
89
89
 
90
- - **Type:** [BriefType](#brieftype)
91
- - **Optional:** `true`
92
- - **Default:** undefined
90
+ - **类型:** [BriefType](#brieftype)
91
+ - **可选:** `true`
92
+ - **默认值:** `undefined`
93
93
 
94
94
  Brief 模式更多配置,如下:
95
95
 
@@ -107,9 +107,9 @@ interface BriefConfig {
107
107
 
108
108
  ### disableClientServer
109
109
 
110
- - **Type:** `boolean`
111
- - **Optional:** `true`
112
- - **Default:** `false`
110
+ - **类型:** `boolean`
111
+ - **可选:** `true`
112
+ - **默认值:** `false`
113
113
 
114
114
  :::tip
115
115
  建议在 CI 环境下将 disableClientServer 设置为 true,否则启动的服务会卡住 pipeline 流程.
@@ -123,9 +123,9 @@ interface BriefConfig {
123
123
 
124
124
  #### enableNativePlugin
125
125
 
126
- - Type: `boolean`
127
- - Optional: true
128
- - Default: false
126
+ - **类型:** `boolean`
127
+ - **可选:** `true`
128
+ - **默认值:** `false`
129
129
 
130
130
  ##### Description
131
131
 
@@ -133,7 +133,7 @@ interface BriefConfig {
133
133
 
134
134
  - enableNativePlugin:是否开启 Rspack 原生插件,开启后可大幅降低 Rsdoctor 自身的分析耗时。
135
135
 
136
- - Example
136
+ - **示例:**
137
137
 
138
138
  ```js
139
139
  new RsdoctorRspackPlugin({
@@ -143,9 +143,9 @@ new RsdoctorRspackPlugin({
143
143
 
144
144
  ### features
145
145
 
146
- - **Type:** [RsdoctorWebpackPluginFeatures](#rsdoctorwebpackpluginfeatures) | [Array\<keyof RsdoctorWebpackPluginFeatures\>](#rsdoctorwebpackpluginfeatures) | [RsdoctorRspackPluginFeatures](#rsdoctorrspackpluginfeatures) | [Array\<keyof RsdoctorRspackPluginFeatures\>](#rsdoctorrspackpluginfeatures)
147
- - **Optional:** `true`
148
- - **Default:** `['loader', 'plugins', 'bundle']`
146
+ - **类型:** [RsdoctorWebpackPluginFeatures](#rsdoctorwebpackpluginfeatures) | [Array\<keyof RsdoctorWebpackPluginFeatures\>](#rsdoctorwebpackpluginfeatures) | [RsdoctorRspackPluginFeatures](#rsdoctorrspackpluginfeatures) | [Array\<keyof RsdoctorRspackPluginFeatures\>](#rsdoctorrspackpluginfeatures)
147
+ - **可选:** `true`
148
+ - **默认值:** `['loader', 'plugins', 'bundle']`
149
149
 
150
150
  #### features values
151
151
 
@@ -195,9 +195,9 @@ import FeaturesRspack from '@zh/shared/features-rspack.md';
195
195
 
196
196
  <Badge text="Version: 0.4.0" type="warning" />
197
197
 
198
- - **Type:** `normal | brief | lite`
199
- - **Optional:** `true`
200
- - **Default:** `normal`
198
+ - **类型:** `normal | brief | lite`
199
+ - **可选:** `true`
200
+ - **默认值:** `normal`
201
201
 
202
202
  选择使用的 Rsdoctor 构建报告模式,有以下几种:
203
203
 
@@ -211,25 +211,25 @@ import ModeIntro from '@zh/shared/mode-intro.md';
211
211
 
212
212
  #### compressData
213
213
 
214
- - **Type:** boolean
215
- - **Optional:** `true`
216
- - **Default:** true
214
+ - **类型:** `boolean`
215
+ - **可选:** `true`
216
+ - **默认值:** `true`
217
217
 
218
218
  compressData 用于配置是否将 [outputDir]/.rsdoctor 下的分析数据进行压缩处理。
219
219
 
220
220
  #### reportCodeType
221
221
 
222
- - Type: `{ noModuleSource?: boolean; noAssetsAndModuleSource?: boolean }`
223
- - Optional: true
224
- - Default: undefined
225
- - Description
222
+ - **类型:** `{ noModuleSource?: boolean; noAssetsAndModuleSource?: boolean }`
223
+ - **可选:** `true`
224
+ - **默认值:** `undefined`
225
+ - **描述:**
226
226
 
227
227
  - 选择输出的分析数据:
228
228
  - 默认是所有完整数据;
229
229
  - noModuleSource: true 是输出除了 module 代码之外的数据,Module 代码即 Bundle 内一个一个文件的打包模块代码。
230
230
  - noAssetsAndModuleSource: true 是输出除了 module 代码和 Assets 产物代码之外的数据。
231
231
 
232
- - Example
232
+ - **示例:**
233
233
 
234
234
  ```js
235
235
  new RsdoctorRspackPlugin({
@@ -239,17 +239,17 @@ new RsdoctorRspackPlugin({
239
239
 
240
240
  #### reportDir
241
241
 
242
- - **Type:** string
243
- - **Optional:** `true`
244
- - **Default:** undefined
242
+ - **类型:** `string`
243
+ - **可选:** `true`
244
+ - **默认值:** `undefined`
245
245
 
246
246
  Rsdoctor 报告输出目录,默认是构建产物输出目录。
247
247
 
248
248
  ### port
249
249
 
250
- - **Type:** `number`
251
- - **Optional:** `true`
252
- - **Default:** `random(3000, 8999)`
250
+ - **类型:** `number`
251
+ - **可选:** `true`
252
+ - **默认值:** `random(3000, 8999)`
253
253
 
254
254
  配置 Rsdoctor 服务的端口。
255
255
 
@@ -267,9 +267,9 @@ Rsdoctor 报告输出目录,默认是构建产物输出目录。
267
267
 
268
268
  ### supports
269
269
 
270
- - **Type:** [Supports Types](#supports-types)
271
- - **Optional:** `true`
272
- - **Default:** `undefined`
270
+ - **类型:** [Supports Types](#supports-types)
271
+ - **可选:** `true`
272
+ - **默认值:** `undefined`
273
273
 
274
274
  该选项是配置 Rsdoctor 是否开启某些细节特性分析能力支持的,例如:是否开启对 BannerPlugin 的兼容能力。
275
275
 
@@ -289,15 +289,15 @@ type ISupport = {
289
289
  开启 BannerPlugin 分析时,请勿在生产版本中使用 Rsdoctor。
290
290
  :::
291
291
 
292
- - default: true.
293
- - type: boolean.
292
+ - **类型:** `boolean`
293
+ - **默认值:** `true`
294
294
 
295
295
  如果开启 `supports.banner` 则会开启 Rsdoctor 对 BannerPlugin 的兼容逻辑。详细请看:[支持 BannerPlugin](../../guide/usage/bundle-size#%E6%94%AF%E6%8C%81-bannerplugin)
296
296
 
297
297
  #### generateTileGraph
298
298
 
299
- - default: true. rspack 中默认值是 false。
300
- - type: boolean.
299
+ - **默认值:** 使用 Rspack 时默认值是 `false`,否则为 `true`
300
+ - **类型:** `boolean`
301
301
 
302
302
  是否开启生成瓦片图的能力,影响是 Bundle Size 页面中是否有 `webpack-bundle-analyzer` 的瓦片图。
303
303
 
@@ -308,8 +308,8 @@ type ISupport = {
308
308
  />
309
309
  #### parseBundle
310
310
 
311
- - default: true.
312
- - type: boolean.
311
+ - **类型:** `boolean`
312
+ - **默认值:** `true`
313
313
 
314
314
  在部分大型仓库中,反解 Bundle 解析执行耗时过大,这是因为 Parse Bundle 的分析利用了 AST 解析与处理。当产物文件过多时,耗时也会增加。如果不需要此功能,可以通过 `supports.parseBundle` 配置进行选择性关闭。示例如下:
315
315
 
@@ -14,7 +14,7 @@ new RsdoctorRspackPlugin({
14
14
 
15
15
  ## Loader 耗时数据不准?
16
16
 
17
- Rsdoctor 提供的 Loader 耗时时间是**预估耗时**,为什么没法统计到准确耗时?是因为我们知道 Loader 执行可能是**异步**函数也可能是**同步**函数,同时,构建器会**并行执行多个**不冲突的 Loader 函数,其中 **JS 是单线程**的,多个 Loader 函数均可能**抢占当前的任务队列**,同时 Loader 函数内的**异步逻辑没法识别**,导致单个 Loader 函数在执行过程中,**可能横跨**多个其他 Loader 的执行过程,所以会存在如下图所示的三种 case:
17
+ Rsdoctor 提供的 Loader 耗时时间是**预估耗时**,为什么没法统计到准确耗时?是因为我们知道 Loader 执行可能是**异步**函数也可能是**同步**函数,同时,打包工具会**并行执行多个**不冲突的 Loader 函数,其中 **JS 是单线程**的,多个 Loader 函数均可能**抢占当前的任务队列**,同时 Loader 函数内的**异步逻辑没法识别**,导致单个 Loader 函数在执行过程中,**可能横跨**多个其他 Loader 的执行过程,所以会存在如下图所示的三种 case:
18
18
 
19
19
  <img
20
20
  src="https://assets.rspack.dev/others/assets/rsdoctor/loader-cases.jpeg"
@@ -8,7 +8,7 @@
8
8
 
9
9
  :::
10
10
 
11
- ### [E1001] Duplicate Packages
11
+ ### [E1001] Duplicate packages
12
12
 
13
13
  #### 规则详情
14
14
 
@@ -94,7 +94,7 @@ enum CheckVersion {
94
94
 
95
95
  点击 「**More**」可以查看对应规则解释。
96
96
 
97
- ### [E1002] Cross Chunks Package
97
+ ### [E1002] Cross chunks package
98
98
 
99
99
  跨 Chunks 的重复包规则能够扫描**不同 `chunks` 中的重复包**。这些重复包也有可能导致打包代码冗余,具体还要看业务逻辑及冗余代码大小。
100
100
 
@@ -108,7 +108,7 @@ enum CheckVersion {
108
108
 
109
109
  可查看 [[E1002] Cross Chunks Packages](../more/rules)
110
110
 
111
- ### [E1003] Loader Performance Optimization
111
+ ### [E1003] Loader performance optimization
112
112
 
113
113
  通过该模块可以比较直观的看到我们项目在编译方面的一些预警信息,有助于我们可以更进一步优化项目的编译性能。
114
114
 
@@ -142,7 +142,7 @@ interface Config {
142
142
  }
143
143
  ```
144
144
 
145
- ### [E1004] ECMA Version Check
145
+ ### [E1004] ECMA version check
146
146
 
147
147
  该规则用于检测不兼容的高级语法。在规则扫描时,优先使用 `browserslist` 的配置;如果未配置 `browserslist`,则需要手动进行检测,示例如下:
148
148
 
@@ -202,7 +202,7 @@ type CheckSyntaxOptions = {
202
202
 
203
203
  更多 `ECMA Version Check` 配置请参考 [ECMA Version Check Options](https://github.com/rspack-contrib/rsbuild-plugin-check-syntax?tab=readme-ov-file#options)
204
204
 
205
- ### [E1005] Default Import Check
205
+ ### [E1005] Default import check
206
206
 
207
207
  通常,Rspack 会自动兼容不同类型的模块,但在某些情况下,兼容性操作可能会失败。例如,当使用 `Default Import` 导入一个 `cjs` 模块时,如果该模块没有兼容的语句(如 `exports.default`),则会出现问题。
208
208
 
@@ -96,7 +96,7 @@ import { execute } from '@rsdoctor/cli';
96
96
 
97
97
  **execute()**
98
98
 
99
- `execute` 异步函数是 Rsdoctor CLI 的执行函数,通过调用 `execute` 函数就会自动解析 [process.argv](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processargv),然后调用不同的命令。
99
+ `execute` 异步函数是 Rsdoctor CLI 的执行函数,通过调用 `execute` 函数就会自动解析 [process.argv](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processargv),然后调用不同的命令。
100
100
 
101
101
  **execute('analyze', \{...\})**
102
102
 
@@ -15,10 +15,10 @@ import { PackageManagerTabs } from '@theme';
15
15
  ### Webpack 项目
16
16
 
17
17
  :::tip
18
- 不支持 Webpack 4 项目。
18
+ Rsdoctor 仅支持 webpack >= 5。
19
19
  :::
20
20
 
21
- 基于 Webpack 的项目,安装以下依赖:
21
+ 基于 webpack 的项目,安装以下依赖:
22
22
 
23
23
  <PackageManagerTabs command="add @rsdoctor/webpack-plugin -D" />
24
24
 
@@ -19,7 +19,7 @@
19
19
 
20
20
  - **`Assets`**:资源是对图像、字体、媒体和其他文件类型的统称,是最终存在于输出文件夹内的文件,同时,每个 Chunk 都有对应的 [Assets 资源](https://webpack.js.org/concepts/under-the-hood/#chunks)。
21
21
  - **`Module`**:一个或多个 Module 组合成了 Chunk。有关 Module 类型的详细信息,请参阅 [Rspack Modules](https://www.rspack.dev/api/modules.html) 和 [Webpack Modules](https://webpack.js.org/concepts/modules/#what-is-a-webpack-module)。
22
- - **`Bundle Size`**:资源产物的最终打包大小,这是构建器处理后的最终大小。
22
+ - **`Bundle Size`**:资源产物的最终打包大小,这是打包工具处理后的最终大小。
23
23
  - **`Module Bundled Source & Size`**:**Module Parsed Source** 是指 **Module** 在打包产物中的最终代码片段,**Module Parsed Size** 是指 **Module** 在打包产物中的最终代码片段的大小。
24
24
  - **`Package Count`**:第三方包的数量。
25
25
  - **`Initial Chunk`**: **initial(初始化)** 是入口起点的主 Chunk,该 chunk 包含入口起点指定的所有模块及其依赖项,与「**按需加载**」的 **Chunk** 资源不同。
@@ -140,17 +140,16 @@
140
140
 
141
141
  Rsdoctor 兼容了对 BannerPlugin 这种添加代码的逻辑,但因为 Rsdoctor 需要添加标记代码,所以没有默认开启,以下两种情况会开启 Rsdoctor BannerPlugin 能力:
142
142
 
143
- 1. 项目在 `rspack.config.j|ts` 或 `webpack.config.j|ts` 中使用了 BannerPlugin;
143
+ 1. 项目在 `rspack.config.(js|ts)` 或 `webpack.config.(js|ts)` 中使用了 BannerPlugin;
144
144
 
145
- 2. 通过 Rsdoctor options 配置 supports.banner 来开启:
145
+ 2. 通过 Rsdoctor options 配置 `supports.banner` 来开启:
146
146
 
147
147
  ```ts
148
- new RsdoctorRspackPlugin (
148
+ new RsdoctorRspackPlugin({
149
149
  supports: {
150
- banner: true
151
- }
152
- )
153
-
150
+ banner: true,
151
+ },
152
+ });
154
153
  ```
155
154
 
156
155
  - 注:如果开启了 `drop_console` 将会影响 Rsdoctor 对 BannerPlugin 的分析,所以可以在 `RSDOCTOR = true` 时,关闭 `drop_console`。
@@ -19,12 +19,12 @@
19
19
 
20
20
  以下是卡片内每个阶段名词的含义以及代码实现:
21
21
 
22
- | 阶段名称 | 描述说明 | 代码实现 |
23
- | ---------------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
- | <b><i>Bootstrap -> BeforeCompile</i></b> | 代表项目从启动到开始编译之前的耗时 | <ul><li>`Webpack` or `Rspack` 项目中:在 **compiler.hooks.beforeCompile** 被调用时上报 [process.uptime()](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processuptime) 作为<b>本阶段耗时</b></li></ul> |
25
- | <b><i>Compile</i></b> | 代表项目的整个编译耗时 | <ul><li>`Webpack` or `Rspack` 项目中:在 **compiler.hooks.beforeCompile** 被调用时的时间点作为<b>开始时间</b>,在 **compiler.hooks.afterCompile** 被调用时的时间点作为<b>结束时间</b></li></ul> |
26
- | <b><i>AfterCompile -> Done</i></b> | 代表编译结束到整个流程结束的耗时 | <ul><li>`Webpack` or `Rspack` 项目中:在 **compiler.hooks.afterCompile** 被调用时的时间点作为<b>开始时间</b>,在 **compiler.hooks.done** 被调用时的时间点作为<b>结束时间</b></li></ul> |
27
- | <b><i>Minify</i></b> | 绝大部分情况下,代表项目编译流程内文件压缩的耗时 | <ul><li>`Webpack` or `Rspack` 项目中:统计 **compilation.hooks.optimizeChunkAssets** 和 **compilation.hooks.processAssets** 每次<b>调用时间之和</b></li></ul> |
22
+ | 阶段名称 | 描述说明 | 代码实现 |
23
+ | ---------------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | <b><i>Bootstrap -> BeforeCompile</i></b> | 代表项目从启动到开始编译之前的耗时 | <ul><li>在 **compiler.hooks.beforeCompile** 被调用时上报 [process.uptime()](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processuptime) 作为<b>本阶段耗时</b></li></ul> |
25
+ | <b><i>Compile</i></b> | 代表项目的整个编译耗时 | <ul><li>在 **compiler.hooks.beforeCompile** 被调用时的时间点作为<b>开始时间</b>,在 **compiler.hooks.afterCompile** 被调用时的时间点作为<b>结束时间</b></li></ul> |
26
+ | <b><i>AfterCompile -> Done</i></b> | 代表编译结束到整个流程结束的耗时 | <ul><li>在 **compiler.hooks.afterCompile** 被调用时的时间点作为<b>开始时间</b>,在 **compiler.hooks.done** 被调用时的时间点作为<b>结束时间</b></li></ul> |
27
+ | <b><i>Minify</i></b> | 绝大部分情况下,代表项目编译流程内文件压缩的耗时 | <ul><li>统计 **compilation.hooks.optimizeChunkAssets** 和 **compilation.hooks.processAssets** 每次<b>调用时间之和</b></li></ul> |
28
28
 
29
29
  ## 使用说明
30
30
 
@@ -56,7 +56,7 @@
56
56
 
57
57
  该部分可以查看导航栏 「Compile Analysis」-> 「Loader Analysis」-> [**Loader Timeline**](./loaders-timeline.mdx) 来查看 Loader 编译耗时时序图。
58
58
 
59
- ### AfterCompile -> Done 耗时详情
59
+ ### AfterCompile -> done 耗时详情
60
60
 
61
61
  通过**点击 `AfterCompile -> Done` 阶段后的数据**会在页面中弹出一个浮层,其内容如下图所示:
62
62
 
@@ -18,7 +18,7 @@
18
18
  | <b><i>errors</i></b> | 代表 Rsdoctor 在当次运行中检测出的 **error** 级别的规则 |
19
19
  | <b><i>warns</i></b> | 代表 Rsdoctor 在当次运行中检测出的 **warn** 级别的规则 |
20
20
  | <b><i>webpack</i></b> | 代表当次运行时获取到的 Webpack 版本 |
21
- | <b><i>cwd</i></b> | 代表当次运行时的进程执行目录,即 [process.cwd()](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processcwd) |
21
+ | <b><i>cwd</i></b> | 代表当次运行时的进程执行目录,即 [process.cwd()](https://nodejs.org/dist/latest-v22.x/docs/api/process.html#processcwd) |
22
22
  | <b><i>cpu</i></b> | 代表 cpu 信息 |
23
23
  | <b><i>memory</i></b> | 代表当次运行时的 memory 信息 |
24
24
  | <b><i>node</i></b> | 代表 [Node.js](https://nodejs.org/) 版本号 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/docs",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-rc.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -30,7 +30,7 @@
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-beta.3"
33
+ "@rsdoctor/types": "1.0.0-rc.0"
34
34
  },
35
35
  "dependencies": {
36
36
  "@rstack-dev/doc-ui": "1.7.2",