Skip to content

Commit 351f07b

Browse files
authored
chore(core): add concatenateModules info for rsppedy (#1127)
1 parent db833cb commit 351f07b

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

packages/document/docs/en/guide/more/faq.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,56 @@ module.exports = {
6161
- Cause: During the build process, the source code information is stored, which exceeds the memory limit. Enabling the `lite` mode can alleviate this issue.
6262
- Difference: The difference between the **lite mode** and the **normal mode** is that the **lite mode** no longer stores the **source code information**, only the **bundled code** is stored. Additionally, the code displayed in the analysis report will only consist of the **bundled code**.
6363

64+
## Bundle analysis page no `Bundled Size`?
65+
66+
### Issue Description
67+
68+
The difference between `Source Size` and `Bundled Size`:
69+
70+
- **Source Size**: The original size of the Module source code file (marked in purple in the image below).
71+
- **Bundled Size**: The final code size of the Module after bundling and minification (marked in cyan in the image below).
72+
73+
<img src="https://assets.rspack.rs/others/assets/rsdoctor/bundle-size-overall.png" />
74+
75+
### Root Cause
76+
77+
When [optimization.concatenateModules](https://rspack.rs/config/optimization#optimizationconcatenatemodules) is set to `true`, Rsdoctor cannot use `acorn` to parse the build artifacts and break down the actual code size of each **Module**, therefore it cannot display the `Bundled Size`.
78+
79+
### Solution
80+
81+
:::danger
82+
**Important Note:** You must check the `RSDOCTOR` environment variable and not modify ConcatenateModules directly! ConcatenateModules is enabled by default in production environments, and disabling it in production builds will increase the bundle size.
83+
:::
84+
85+
When enabling Rsdoctor analysis, set **concatenateModules to false** as shown below. **Note: Disabling `concatenateModules` will slightly increase bundle size, creating differences from production builds.**
86+
87+
```js rspack.config.mjs
88+
export default {
89+
optimization: {
90+
concatenateModules:
91+
process.env.NODE_ENV === 'production' && !process.env.RSDOCTOR, // Must check RSDOCTOR environment variable, do not modify concatenateModules directly!
92+
},
93+
};
94+
```
95+
96+
- In the rspeedy project, configure it in `rspeedy.config.ts`:
97+
98+
```js rspeedy.config.ts
99+
export default {
100+
tools: {
101+
rspack(config, { env }) {
102+
if (process.env.RSDOCTOR === 'true') {
103+
config.optimization = {
104+
...config.optimization,
105+
concatenateModules: false,
106+
},
107+
return config
108+
}
109+
},
110+
},
111+
};
112+
```
113+
64114
## The loader of CssExtractRspackPlugin takes too long
65115

66116
When using Rsdoctor to analyze the compilation time of Rspack projects, you may find that the loader of [CssExtractRspackPlugin](https://rspack.rs/plugins/rspack/css-extract-rspack-plugin) takes a long time. However, this figure does not represent the actual time taken by the CssExtractRspackPlugin's loader; it also includes the time taken by other loaders involved in compiling this module.

packages/document/docs/zh/guide/more/faq.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,56 @@ module.exports = {
5959
- 原因:因为构建过程中,存储了源码信息,超过了内存,所以开启 `lite` 模式可以缓解。
6060
- 区别:`lite` 模式和普通模式的区别就是不再存储**源码信息**,只存储**打包后的代码**,同时分析报告上的代码也将**只有打包后的代码**
6161

62+
## 产物分析界面没有 `Bundled Size` 怎么办?
63+
64+
### 问题说明
65+
66+
`Source Size``Bundled Size` 的区别:
67+
68+
- **Source Size**:Module 文件源码的原始大小(如下图紫色标识)。
69+
- **Bundled Size**:经过打包及压缩后的 Module 的最终代码大小(如下图青色标识)。
70+
71+
<img src="https://assets.rspack.rs/others/assets/rsdoctor/bundle-size-overall.png" />
72+
73+
### 原因分析
74+
75+
[optimization.concatenateModules](https://rspack.rs/zh/config/optimization#optimizationconcatenatemodules) 配置为 `true` 时,Rsdoctor 无法通过 `acorn` 解析产物来分解出每个 **Module** 的实际代码大小,因此无法显示 `Bundled Size`
76+
77+
### 解决方案
78+
79+
:::danger
80+
**重要提醒:** 必须判断 `RSDOCTOR` 环境变量,不能直接修改 ConcatenateModules!线上环境默认开启 ConcatenateModules,线上构建环境中关闭会导致产物体积变大。
81+
:::
82+
83+
**在开启 Rsdoctor 分析时,配置 concatenateModules 为 false**,如下所示。**同时要注意,关闭 concatenateModules 一定会导致产物体积略微变大,与线上环境的体积有一些差异。**
84+
85+
```js rspack.config.mjs
86+
export default {
87+
optimization: {
88+
concatenateModules:
89+
process.env.NODE_ENV === 'production' && !process.env.RSDOCTOR, // 需要判断 RSDOCTOR 环境变量,不可以直接修改 concatenateModules!
90+
},
91+
};
92+
```
93+
94+
- rspeedy 项目中,在 `rspeedy.config.ts` 中配置:
95+
96+
```js rspeedy.config.ts
97+
export default {
98+
tools: {
99+
rspack(config, { env }) {
100+
if (process.env.RSDOCTOR === 'true') {
101+
config.optimization = {
102+
...config.optimization,
103+
concatenateModules: false,
104+
},
105+
return config
106+
}
107+
},
108+
},
109+
};
110+
```
111+
62112
## CssExtractRspackPlugin 的 loader 耗时过长问题
63113

64114
在使用 Rsdoctor 对 Rspack 项目进行编译耗时分析时,可能会发现 [CssExtractRspackPlugin](https://rspack.rs/plugins/rspack/css-extract-rspack-plugin) 的 loader 耗时较长。然而,这个数值并不代表 CssExtractRspackPlugin 的 loader 的真实耗时,它还包含了对本模块编译的其他 loader 的耗时。

packages/rspack-plugin/src/plugin.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ export class RsdoctorRspackPlugin<Rules extends Linter.ExtendRuleData[]>
197197
public done = async (
198198
compiler: Plugin.BaseCompilerType<'rspack'>,
199199
): Promise<void> => {
200+
if (
201+
compiler.name?.toLowerCase() === 'lynx' &&
202+
compiler.options.optimization?.concatenateModules !== false
203+
) {
204+
logger.info(
205+
`${chalk.yellow('Please disable concatenateModules when RSDOCTOR = true to accurately check bundled size.')} Details: https://rsdoctor.rs/guide/more/faq#bundle-analysis-page-nobundled-size`,
206+
);
207+
}
208+
200209
await this.sdk.bootstrap();
201210

202211
this.sdk.addClientRoutes([

0 commit comments

Comments
 (0)