@rsdoctor/docs 0.3.5 → 0.3.7

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.
@@ -0,0 +1,133 @@
1
+ # Rsdoctor v0.2-0.3 Release Note
2
+
3
+ Rsdoctor v0.3 已经发布啦!
4
+
5
+ Rsdoctor v0.3 的新特性有:
6
+
7
+ - 自定义拓展规则:用户可以通过接口定制特有的规则检查。
8
+ - 支持 Banner Plugin:增加了对 Banner Plugin 的支持,该插件会对产物代码添加模板包裹,因此 Rsdoctor 支持了变化后产物代码的分析。
9
+ - 支持 ESM Loader 分析:支持了对 ESM Loader 的分析,以提升针对 Rspack 的编译分析能力。
10
+
11
+ ## 自定义拓展规则
12
+
13
+ 考虑到用户会有特有的规则定义需求,Rsdoctor 除了内部已有的规则外,还提供了外部接口供用户定制自己的规则检查。外部扩展接口通过 `extends` 字段配置到 Rsdoctor 插件上,配置也放在 `rules` 字段内。详情请查看:[自定义拓展规则](/guide/custom/rule-custom)。
14
+
15
+ 此外,利用自定义规则的方式还可以用于用户数据收集和上报。请参阅[数据上报](/guide/custom/upload-data)。
16
+
17
+ - 示例:
18
+
19
+ ```ts
20
+ // src/rules/assets-count-limit.ts
21
+ import { defineRule } from '@rsdoctor/core/rules';
22
+
23
+ export const AssetsCountLimit = defineRule(() => ({
24
+ meta: {
25
+ category: 'bundle',
26
+ severity: 'Warn',
27
+ title: 'assets-count-limit',
28
+ defaultConfig: {
29
+ limit: 10,
30
+ },
31
+ },
32
+ check({ chunkGraph, report, ruleConfig }) {
33
+ const assets = chunkGraph.getAssets();
34
+
35
+ if (assets.length > ruleConfig.limit) {
36
+ report({
37
+ message: 'The count of assets is bigger than limit',
38
+ detail: {
39
+ type: 'link',
40
+ link: 'https://rsdoctor.dev/zh/guide/start/quick-start', // This link just for show case.
41
+ },
42
+ });
43
+ }
44
+ },
45
+ }));
46
+ ```
47
+
48
+ ```ts
49
+ // rsbuild.config.ts
50
+ import { AssetsCountLimit } from './rules/assets-count-limit';
51
+
52
+ export default {
53
+ tools: {
54
+ bundlerChain: (chain) => {
55
+ chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
56
+ {
57
+ linter: {
58
+ level: 'Error',
59
+ extends: [AssetsCountLimit],
60
+ rules: {
61
+ 'assets-count-limit': [
62
+ 'on',
63
+ {
64
+ limit: 1, // rule custom configs
65
+ },
66
+ ],
67
+ },
68
+ },
69
+ },
70
+ ]);
71
+ },
72
+ },
73
+ };
74
+ ```
75
+
76
+ ## 支持 Banner Plugin
77
+
78
+ 由于 Rspack 和 Webpack 都支持 BannerPlugin,且 BannerPlugin 可在生成的 chunk 顶部或尾部添加指定内容的代码段,这会影响到对 Bundle 的解析能力。因此,Rsdoctor 增加了 Banner Plugin 的支持。
79
+
80
+ 详情请查看[支持 BannerPlugin](/guide/usage/bundle-size#%E6%94%AF%E6%8C%81-bannerplugin)
81
+
82
+ ### 支持 ESM Loader
83
+
84
+ 自 Rspack@0.7.3 开始,支持以 `.js` 为后缀且 `package.json` 中配置 `type: module` 的 ESM Loader 执行([相关 issue](https://github.com/web-infra-dev/rspack/issues/5735))。因此,Rsdoctor 也支持 ESM Loader 的分析,主要支持以下两种类型:
85
+
86
+ 1. 以 `.mjs` 为后缀的 ESM Loader。
87
+ 2. 以 `.js` 为后缀且 `package.json` 中配置 `type: module` 的 ESM Loader。
88
+
89
+ ## 支持 port 定义
90
+
91
+ Rsdoctor 新增了配置服务端口的能力。[详情请参阅](/config/options/options#port)。
92
+
93
+ - 示例:
94
+
95
+ ```ts
96
+ chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
97
+ {
98
+ port: 8888, // port
99
+ },
100
+ ]);
101
+ ```
102
+
103
+ ## 支持 Parse Bundle 配置
104
+
105
+ 在部分大型仓库中,反解 Bundle 解析执行耗时过大,这是因为 Parse Bundle 的分析利用了 AST 解析与处理。当产物文件过多时,耗时也会增加。如果不需要此功能,可以通过 `supports.parseBundle` 配置进行选择性关闭。示例如下:
106
+
107
+ ```ts
108
+ chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
109
+ {
110
+ supports: {
111
+ parseBundle: false,
112
+ },
113
+ },
114
+ ]);
115
+ ```
116
+
117
+ 关闭 Parse Bundle 能力只会影响是否能查看到 Bundle 中 Module 的最终打包大小(Bundled Size)及最终打包代码(Bundled Code)。
118
+
119
+ <div style={{ display: 'flex' }}>
120
+ <img
121
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundled-size.jpeg"
122
+ height="300px"
123
+ width="400px"
124
+ style={{ margin: 'auto' }}
125
+ />
126
+
127
+ <img
128
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundled-code.png"
129
+ height="300px"
130
+ width="500px"
131
+ style={{ margin: 'auto' }}
132
+ />
133
+ </div>
@@ -149,7 +149,9 @@ import FeaturesRspack from '@zh/shared/features-rspack.md';
149
149
 
150
150
  ```ts
151
151
  type ISupport = {
152
- banner: boolean;
152
+ banner?: boolean;
153
+ parseBundle?: boolean;
154
+ generateTileGraph?: boolean;
153
155
  };
154
156
  ```
155
157
 
@@ -159,8 +161,59 @@ type ISupport = {
159
161
  开启 BannerPlugin 分析时,请勿在生产版本中使用 Rsdoctor。
160
162
  :::
161
163
 
164
+ - default: true.
165
+ - type: boolean.
166
+
162
167
  如果开启 `supports.banner` 则会开启 Rsdoctor 对 BannerPlugin 的兼容逻辑。详细请看:[支持 BannerPlugin](../../guide/usage/bundle-size#%E6%94%AF%E6%8C%81-bannerplugin)
163
168
 
169
+ #### parseBundle
170
+
171
+ - default: true.
172
+ - type: boolean.
173
+
174
+ 在部分大型仓库中,反解 Bundle 解析执行耗时过大,这是因为 Parse Bundle 的分析利用了 AST 解析与处理。当产物文件过多时,耗时也会增加。如果不需要此功能,可以通过 `supports.parseBundle` 配置进行选择性关闭。示例如下:
175
+
176
+ ```ts
177
+ chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
178
+ {
179
+ supports: {
180
+ parseBundle: false,
181
+ },
182
+ },
183
+ ]);
184
+ ```
185
+
186
+ 关闭 Parse Bundle 能力只会影响是否能查看到 Bundle 中 Module 的最终打包大小(Bundled Size)及最终打包代码(Bundled Code):
187
+
188
+ <div style={{ display: 'flex' }}>
189
+ <img
190
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundled-size.jpeg"
191
+ height="300px"
192
+ width="400px"
193
+ style={{ margin: 'auto' }}
194
+ />
195
+
196
+ <img
197
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundled-code.png"
198
+ height="300px"
199
+ width="500px"
200
+ style={{ margin: 'auto' }}
201
+ />
202
+ </div>
203
+
204
+ #### generateTileGraph
205
+
206
+ - default: true. 在 rspack 中默认值是 false。
207
+ - type: boolean.
208
+
209
+ 是否开启生成瓦片图的能力,影响是 Bundle Size 页面中是否有 `webpack-bundle-analyzer` 的瓦片图。
210
+
211
+ <img
212
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-size-tile-graph.png"
213
+ width="500px"
214
+ style={{ margin: 'auto' }}
215
+ />
216
+
164
217
  ### port
165
218
 
166
219
  - **Type:** `number`
@@ -9,6 +9,11 @@
9
9
  "name": "usage",
10
10
  "label": "功能介绍"
11
11
  },
12
+ {
13
+ "type": "dir",
14
+ "name": "custom",
15
+ "label": "自定义"
16
+ },
12
17
  {
13
18
  "type": "dir",
14
19
  "name": "more",
@@ -0,0 +1 @@
1
+ ["rule-custom", "upload-data"]