@rsdoctor/docs 1.0.0-beta.0 → 1.0.0-beta.2
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/docs/en/blog/release/release-note-0_3.mdx +2 -2
- package/docs/en/config/options/options.mdx +55 -33
- package/docs/en/guide/_meta.json +2 -2
- package/docs/en/guide/more/faq.mdx +4 -4
- package/docs/en/guide/rules/_meta.json +1 -0
- package/docs/en/guide/rules/rules.mdx +281 -0
- package/docs/en/guide/usage/bundle-alerts.mdx +9 -40
- package/docs/en/guide/usage/compile-alerts.mdx +6 -6
- package/docs/en/guide/usage/rule-config.mdx +15 -91
- package/docs/en/index.md +1 -35
- package/docs/public/bundle-alerts.png +0 -0
- package/docs/public/cross-chunks-package.png +0 -0
- package/docs/zh/blog/release/release-note-0_3.mdx +2 -2
- package/docs/zh/config/options/options.mdx +48 -26
- package/docs/zh/guide/_meta.json +2 -2
- package/docs/zh/guide/more/faq.mdx +4 -4
- package/docs/zh/guide/rules/_meta.json +1 -0
- package/docs/zh/guide/rules/rules.mdx +281 -0
- package/docs/zh/guide/usage/bundle-alerts.mdx +8 -40
- package/docs/zh/guide/usage/compile-alerts.mdx +2 -2
- package/docs/zh/guide/usage/resolver.mdx +1 -1
- package/docs/zh/guide/usage/rule-config.mdx +11 -88
- package/docs/zh/index.md +1 -35
- package/package.json +5 -5
- package/docs/en/guide/custom/_meta.json +0 -1
- package/docs/zh/guide/custom/_meta.json +0 -1
- /package/docs/en/guide/{custom → rules}/rule-custom.mdx +0 -0
- /package/docs/en/guide/{custom → rules}/upload-data.mdx +0 -0
- /package/docs/zh/guide/{custom → rules}/rule-custom.mdx +0 -0
- /package/docs/zh/guide/{custom → rules}/upload-data.mdx +0 -0
package/docs/en/index.md
CHANGED
|
@@ -1,38 +1,4 @@
|
|
|
1
1
|
---
|
|
2
2
|
pageType: home
|
|
3
|
-
|
|
4
|
-
hero:
|
|
5
|
-
name: Rsdoctor
|
|
6
|
-
text: Analyzer for Rspack & Webpack
|
|
7
|
-
tagline: Visualize the building process
|
|
8
|
-
actions:
|
|
9
|
-
- theme: brand
|
|
10
|
-
text: Introduction
|
|
11
|
-
link: /guide/start/intro
|
|
12
|
-
- theme: alt
|
|
13
|
-
text: Quick Start
|
|
14
|
-
link: /guide/start/quick-start
|
|
15
|
-
image:
|
|
16
|
-
src: https://assets.rspack.dev/rsdoctor/rsdoctor-logo-960x960.png
|
|
17
|
-
alt: Rsdoctor Logo
|
|
18
|
-
|
|
19
|
-
features:
|
|
20
|
-
- title: Unlimited Framework
|
|
21
|
-
details: Rsdoctor support all projects built on Webpack or Rspack.
|
|
22
|
-
icon: 🛠️
|
|
23
|
-
- title: Compile’s Time
|
|
24
|
-
details: To display the compile execution time and process in the form of a timing diagram.
|
|
25
|
-
icon: 🚀
|
|
26
|
-
- title: Compile’s Actions
|
|
27
|
-
details: Visually view the compilation changes of each file in each loader.
|
|
28
|
-
icon: 🦄
|
|
29
|
-
- title: Bundle Analysis
|
|
30
|
-
details: Visually view the bundles & modules relationship, module reference relationship and repeated packages in detail.
|
|
31
|
-
icon: 🎯
|
|
32
|
-
- title: Bundle Diff
|
|
33
|
-
details: Through comparison, the deterioration and change of the product are found.
|
|
34
|
-
icon: 🎨
|
|
35
|
-
- title: Build Scan
|
|
36
|
-
details: Built-in build rule scanning, and also supports custom rules.
|
|
37
|
-
icon: 🔍
|
|
3
|
+
titleSuffix: ' - Build Analyzer'
|
|
38
4
|
---
|
|
Binary file
|
|
Binary file
|
|
@@ -10,9 +10,9 @@ Rsdoctor v0.3 的新特性有:
|
|
|
10
10
|
|
|
11
11
|
## 自定义拓展规则
|
|
12
12
|
|
|
13
|
-
考虑到用户会有特有的规则定义需求,Rsdoctor 除了内部已有的规则外,还提供了外部接口供用户定制自己的规则检查。外部扩展接口通过 `extends` 字段配置到 Rsdoctor 插件上,配置也放在 `rules` 字段内。详情请查看:[自定义拓展规则](/guide/
|
|
13
|
+
考虑到用户会有特有的规则定义需求,Rsdoctor 除了内部已有的规则外,还提供了外部接口供用户定制自己的规则检查。外部扩展接口通过 `extends` 字段配置到 Rsdoctor 插件上,配置也放在 `rules` 字段内。详情请查看:[自定义拓展规则](/guide/rules/rule-custom)。
|
|
14
14
|
|
|
15
|
-
此外,利用自定义规则的方式还可以用于用户数据收集和上报。请参阅[数据上报](/guide/
|
|
15
|
+
此外,利用自定义规则的方式还可以用于用户数据收集和上报。请参阅[数据上报](/guide/rules/upload-data)。
|
|
16
16
|
|
|
17
17
|
- 示例:
|
|
18
18
|
|
|
@@ -153,15 +153,16 @@ import ModeIntro from '@zh/shared/mode-intro.md';
|
|
|
153
153
|
|
|
154
154
|
<ModeIntro />
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
#### banner
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
:::danger
|
|
159
|
+
开启 BannerPlugin 分析时,请勿在生产版本中使用 Rsdoctor。
|
|
160
|
+
:::
|
|
159
161
|
|
|
160
|
-
-
|
|
161
|
-
-
|
|
162
|
-
- **Default:** undefined
|
|
162
|
+
- default: true.
|
|
163
|
+
- type: boolean.
|
|
163
164
|
|
|
164
|
-
Rsdoctor
|
|
165
|
+
如果开启 `supports.banner` 则会开启 Rsdoctor 对 BannerPlugin 的兼容逻辑。详细请看:[支持 BannerPlugin](../../guide/usage/bundle-size#%E6%94%AF%E6%8C%81-bannerplugin)
|
|
165
166
|
|
|
166
167
|
### brief
|
|
167
168
|
|
|
@@ -185,7 +186,11 @@ interface BriefConfig {
|
|
|
185
186
|
}
|
|
186
187
|
```
|
|
187
188
|
|
|
188
|
-
###
|
|
189
|
+
### output
|
|
190
|
+
|
|
191
|
+
<Badge text="Version: 1.0.0" type="warning" />
|
|
192
|
+
|
|
193
|
+
#### reportCodeType
|
|
189
194
|
|
|
190
195
|
- Type: `{ noModuleSource?: boolean; noAssetsAndModuleSource?: boolean }`
|
|
191
196
|
- Optional: true
|
|
@@ -205,6 +210,42 @@ new RsdoctorRspackPlugin({
|
|
|
205
210
|
}),
|
|
206
211
|
```
|
|
207
212
|
|
|
213
|
+
#### reportDir
|
|
214
|
+
|
|
215
|
+
- **Type:** string
|
|
216
|
+
- **Optional:** `true`
|
|
217
|
+
- **Default:** undefined
|
|
218
|
+
|
|
219
|
+
Rsdoctor 报告输出目录,默认是构建产物输出目录。
|
|
220
|
+
|
|
221
|
+
#### compressData
|
|
222
|
+
|
|
223
|
+
- **Type:** boolean
|
|
224
|
+
- **Optional:** `true`
|
|
225
|
+
- **Default:** true
|
|
226
|
+
|
|
227
|
+
compressData 用于配置是否将 [outputDir]/.rsdoctor 下的分析数据进行压缩处理。
|
|
228
|
+
|
|
229
|
+
### port
|
|
230
|
+
|
|
231
|
+
- **Type:** `number`
|
|
232
|
+
- **Optional:** `true`
|
|
233
|
+
- **Default:** `random(3000, 8999)`
|
|
234
|
+
|
|
235
|
+
配置 Rsdoctor 服务的端口。
|
|
236
|
+
|
|
237
|
+
### ~~reportCodeType [**Deprecated**]~~
|
|
238
|
+
|
|
239
|
+
<Badge text="Deprecated" type="warning" />
|
|
240
|
+
|
|
241
|
+
请使用 [output.reportCodeType](#reportcodetype)
|
|
242
|
+
|
|
243
|
+
### ~~reportDir [**Deprecated**]~~
|
|
244
|
+
|
|
245
|
+
<Badge text="Deprecated" type="warning" />
|
|
246
|
+
|
|
247
|
+
请使用 [output.reportDir](#reportDir)
|
|
248
|
+
|
|
208
249
|
### supports
|
|
209
250
|
|
|
210
251
|
- **Type:** [Supports Types](#supports-types)
|
|
@@ -223,17 +264,6 @@ type ISupport = {
|
|
|
223
264
|
};
|
|
224
265
|
```
|
|
225
266
|
|
|
226
|
-
#### banner
|
|
227
|
-
|
|
228
|
-
:::danger
|
|
229
|
-
开启 BannerPlugin 分析时,请勿在生产版本中使用 Rsdoctor。
|
|
230
|
-
:::
|
|
231
|
-
|
|
232
|
-
- default: true.
|
|
233
|
-
- type: boolean.
|
|
234
|
-
|
|
235
|
-
如果开启 `supports.banner` 则会开启 Rsdoctor 对 BannerPlugin 的兼容逻辑。详细请看:[支持 BannerPlugin](../../guide/usage/bundle-size#%E6%94%AF%E6%8C%81-bannerplugin)
|
|
236
|
-
|
|
237
267
|
#### parseBundle
|
|
238
268
|
|
|
239
269
|
- default: true.
|
|
@@ -281,11 +311,3 @@ chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
|
|
|
281
311
|
width="500px"
|
|
282
312
|
style={{ margin: 'auto' }}
|
|
283
313
|
/>
|
|
284
|
-
|
|
285
|
-
### port
|
|
286
|
-
|
|
287
|
-
- **Type:** `number`
|
|
288
|
-
- **Optional:** `true`
|
|
289
|
-
- **Default:** `random(3000, 8999)`
|
|
290
|
-
|
|
291
|
-
配置 Rsdoctor 服务的端口。
|
package/docs/zh/guide/_meta.json
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
当我们**只需要** Rsdoctor 内 [Bundle Size](../usage/bundle-size) 分析产物大小的功能时,我们可以在接入 Rsdoctor 插件时配置对应的 [Features](/config/options/options) 配置项,参考下方代码:
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
import {
|
|
8
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
9
9
|
|
|
10
|
-
new
|
|
10
|
+
new RsdoctorRspackPlugin({
|
|
11
11
|
features: ['bundle'], // 代表只开启 bundle size 的功能分析
|
|
12
12
|
});
|
|
13
13
|
```
|
|
@@ -42,13 +42,13 @@ Rsdoctor 提供的 Loader 耗时时间是**预估耗时**,为什么没法统
|
|
|
42
42
|
下面示例是开启了 lite 模式以及构建时和构建产物分析:
|
|
43
43
|
|
|
44
44
|
```js
|
|
45
|
-
const {
|
|
45
|
+
const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
|
|
46
46
|
|
|
47
47
|
// adding the plugin to your configuration
|
|
48
48
|
module.exports = {
|
|
49
49
|
// ...
|
|
50
50
|
plugins: [
|
|
51
|
-
new
|
|
51
|
+
new RsdoctorRspackPlugin({
|
|
52
52
|
disableClientServer: false,
|
|
53
53
|
features: ['lite', 'loader', 'plugins', 'bundle'],
|
|
54
54
|
}),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["rules", "rule-custom", "upload-data"]
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# 内置规则
|
|
2
|
+
|
|
3
|
+
## 功能介绍
|
|
4
|
+
|
|
5
|
+
:::tip
|
|
6
|
+
|
|
7
|
+
`linter` 的类型定义请参见本文档的[Linter 类型定义](#linter-%E7%B1%BB%E5%9E%8B%E5%AE%9A%E4%B9%89)。
|
|
8
|
+
|
|
9
|
+
:::
|
|
10
|
+
|
|
11
|
+
### [E1001] Duplicate Packages
|
|
12
|
+
|
|
13
|
+
#### 规则详情
|
|
14
|
+
|
|
15
|
+
- `Duplicate Packages` 卡片上展示了项目重复第三方包数目。点击图片可以查看重复第三方包的具体详情。注:这里的第三方都是被打包的第三方包。
|
|
16
|
+
|
|
17
|
+
<div style={{ display: 'flex' }}>
|
|
18
|
+
<img
|
|
19
|
+
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-1.png"
|
|
20
|
+
height="200px"
|
|
21
|
+
width="260px"
|
|
22
|
+
style={{ margin: 'auto' }}
|
|
23
|
+
/>
|
|
24
|
+
<img
|
|
25
|
+
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-2.png"
|
|
26
|
+
height="300px"
|
|
27
|
+
width="340px"
|
|
28
|
+
style={{ margin: 'auto' }}
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
- 重复包预警卡片
|
|
33
|
+
|
|
34
|
+
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alerts.png" />
|
|
35
|
+
|
|
36
|
+
- 点击图标展开重复包详情,可以看到:重复包的包名、版本、大小、引用文件。
|
|
37
|
+
|
|
38
|
+
- 点击最右侧 **「Show Relations」** 可以查看具体这个第三方的引用链路和对应的引用文件代码位置。
|
|
39
|
+
|
|
40
|
+
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-relations.png" />
|
|
41
|
+
|
|
42
|
+
- 点击最右侧 **「!(叹号)」** 图标,可以查看重复第三方包的规则的具体解释。
|
|
43
|
+
|
|
44
|
+
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-rule.png" />
|
|
45
|
+
|
|
46
|
+
#### 配置
|
|
47
|
+
|
|
48
|
+
- 配置示例:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
52
|
+
|
|
53
|
+
export default {
|
|
54
|
+
plugin: [
|
|
55
|
+
new RsdoctorRspackPlugin({
|
|
56
|
+
linter: {
|
|
57
|
+
level: 'Error',
|
|
58
|
+
extends: [],
|
|
59
|
+
rules: {
|
|
60
|
+
'duplicate-package': [
|
|
61
|
+
'Error',
|
|
62
|
+
{
|
|
63
|
+
checkVersion: 'minor',
|
|
64
|
+
ignore: ['chalk', '@babel/runtime'],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
##### 类型
|
|
75
|
+
|
|
76
|
+
- **ignore**: 配置需要忽略的 Packages。
|
|
77
|
+
- **checkVersion**: 是指要检查的最大版本级别,例如:如果设置了 `minor`,那么重复包将不再检查 `major` 级别的差异。**默认为 `major`**。
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
interface Config {
|
|
81
|
+
checkVersion: keyof typeof CheckVersion;
|
|
82
|
+
ignore: string[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
enum CheckVersion {
|
|
86
|
+
null = 0,
|
|
87
|
+
prerelease = 0x1,
|
|
88
|
+
prepatch = 0x10,
|
|
89
|
+
patch = 0x100,
|
|
90
|
+
preminor = 0x1000,
|
|
91
|
+
minor = 0x10000,
|
|
92
|
+
premajor = 0x100000,
|
|
93
|
+
major = 0x1000000,
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### 重复包优化问题
|
|
98
|
+
|
|
99
|
+
请查看[重复包优化方案](../../blog/topic/duplicate-pkg-problem)。
|
|
100
|
+
|
|
101
|
+
点击 「**More**」可以查看对应规则解释。
|
|
102
|
+
|
|
103
|
+
### [E1002] Cross Chunks Package
|
|
104
|
+
|
|
105
|
+
跨 Chunks 的重复包规则能够扫描**不同 `chunks` 中的重复包**。这些重复包也有可能导致打包代码冗余,具体还要看业务逻辑及冗余代码大小。
|
|
106
|
+
|
|
107
|
+
- 展示
|
|
108
|
+
- Module 是指被重复打在多个 chunk 中的 Module。
|
|
109
|
+
- Chunks 则是被重复打包的产物。
|
|
110
|
+
|
|
111
|
+
<img src="/cross-chunks-package.png" />
|
|
112
|
+
|
|
113
|
+
#### 解决方案
|
|
114
|
+
|
|
115
|
+
可查看 [[E1002] Cross Chunks Packages](../more/rules)
|
|
116
|
+
|
|
117
|
+
### [E1003] Loader Performance Optimization
|
|
118
|
+
|
|
119
|
+
通过该模块可以比较直观的看到我们项目在编译方面的一些预警信息,有助于我们可以更进一步优化项目的编译性能。
|
|
120
|
+
|
|
121
|
+
#### 解决方案
|
|
122
|
+
|
|
123
|
+
可查看 [[E1003] Loader Performance Optimization](../more/rules)
|
|
124
|
+
|
|
125
|
+
#### 配置类型
|
|
126
|
+
|
|
127
|
+
- **ignore**:可以包含字符串或正则表达式,用于指定需要被忽略的 loader 。
|
|
128
|
+
- **threshold**: 表示 Loader 的总耗时阈值,单位为毫秒(millisecond)。如果 Loader 的执行时间超过这个阈值,则可能会触发警告或错误。默认值为5000毫秒。
|
|
129
|
+
- **extensions**:字符串或正则表达式,用于指定在规则检查中需要匹配的文件扩展名。默认情况下,它包括常见的文件类型,如 js、css、jpg、jpeg、png、gif、webp 和 svg。
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
interface Config {
|
|
133
|
+
/**
|
|
134
|
+
* loaders which should be ignore.
|
|
135
|
+
*/
|
|
136
|
+
ignore: (string | RegExp)[];
|
|
137
|
+
/**
|
|
138
|
+
* threshold which the loader total costs.
|
|
139
|
+
* @unit millisecond
|
|
140
|
+
* @default 5000
|
|
141
|
+
*/
|
|
142
|
+
threshold: number;
|
|
143
|
+
/**
|
|
144
|
+
* the file extensions which will be match in rule check.
|
|
145
|
+
* @default ["js", "css", "jpg", "jpeg", "png", "gif", "webp", "svg"]
|
|
146
|
+
*/
|
|
147
|
+
extensions: (string | RegExp)[];
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### [E1004] ECMA Version Check
|
|
152
|
+
|
|
153
|
+
该规则用于检测不兼容的高级语法。在规则扫描时,优先使用 `browserslist` 的配置;如果未配置 `browserslist`,则需要手动进行检测,示例如下:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
157
|
+
|
|
158
|
+
export default {
|
|
159
|
+
plugin: [
|
|
160
|
+
new RsdoctorRspackPlugin({
|
|
161
|
+
linter: {
|
|
162
|
+
rules: {
|
|
163
|
+
'ecma-version-check': [
|
|
164
|
+
'Warn',
|
|
165
|
+
{
|
|
166
|
+
ecmaVersion: 2015,
|
|
167
|
+
// targets: ["chrome >= 53"],
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
],
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### 类型定义
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
type CheckSyntaxOptions = {
|
|
181
|
+
/**
|
|
182
|
+
* The target browser range of the project.
|
|
183
|
+
* Its value is a standard browserslist array.
|
|
184
|
+
*/
|
|
185
|
+
targets?: string[];
|
|
186
|
+
/**
|
|
187
|
+
* Used to exclude a portion of source files during detection.
|
|
188
|
+
* You can pass in one or more regular expressions to match the paths of source files.
|
|
189
|
+
*/
|
|
190
|
+
exclude?: CheckSyntaxExclude;
|
|
191
|
+
/**
|
|
192
|
+
* Used to exclude files by output path before detection.
|
|
193
|
+
* You can pass in one or more regular expressions to match the paths of source files.
|
|
194
|
+
*/
|
|
195
|
+
excludeOutput?: CheckSyntaxExclude;
|
|
196
|
+
/**
|
|
197
|
+
* The minimum ECMAScript syntax version that can be used in the build artifact.
|
|
198
|
+
* The priority of `ecmaVersion` is higher than `targets`.
|
|
199
|
+
*/
|
|
200
|
+
ecmaVersion?: EcmaVersion;
|
|
201
|
+
/**
|
|
202
|
+
* Used to ignore specified syntax error messages after detection.
|
|
203
|
+
* You can pass in one or more error message types to ignore.
|
|
204
|
+
*/
|
|
205
|
+
excludeErrorLogs?: SyntaxErrorKey[];
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
更多 `ECMA Version Check` 配置请参考 [ECMA Version Check Options](https://github.com/rspack-contrib/rsbuild-plugin-check-syntax?tab=readme-ov-file#options)
|
|
210
|
+
|
|
211
|
+
### [E1005] Default Import Check
|
|
212
|
+
|
|
213
|
+
通常,Rspack 会自动兼容不同类型的模块,但在某些情况下,兼容性操作可能会失败。例如,当使用 `Default Import` 导入一个 `cjs` 模块时,如果该模块没有兼容的语句(如 `exports.default`),则会出现问题。
|
|
214
|
+
|
|
215
|
+
#### 解决方案
|
|
216
|
+
|
|
217
|
+
可查看 [[E1005] Default Import Check](../more/rules)
|
|
218
|
+
|
|
219
|
+
#### 配置
|
|
220
|
+
|
|
221
|
+
- **ignore**:配置忽略一些引入的文件。
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
interface Config {
|
|
225
|
+
/** Packages that need to be ignored */
|
|
226
|
+
ignore: string[];
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Linter 类型定义
|
|
231
|
+
|
|
232
|
+
- `linter`字段的类型如下:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
/** 校验器选项 */
|
|
236
|
+
interface Options {
|
|
237
|
+
rules?: RulesMap;
|
|
238
|
+
level?: SeverityString;
|
|
239
|
+
extends?: ExtendRuleData[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 校验等级
|
|
244
|
+
* - `'Warn'`时只运行类别为`'Warn'`的规则
|
|
245
|
+
* - `'Error'`时运行全部规则
|
|
246
|
+
*/
|
|
247
|
+
type SeverityString = 'Warn' | 'Error';
|
|
248
|
+
|
|
249
|
+
/** 规则等级 */
|
|
250
|
+
type SeverityInput = SeverityString | 'off' | 'on';
|
|
251
|
+
|
|
252
|
+
/** 规则配置 */
|
|
253
|
+
type RulesMap = Record<string, RuleConfigItem>;
|
|
254
|
+
|
|
255
|
+
/** 单规则配置 */
|
|
256
|
+
type RuleConfigItem =
|
|
257
|
+
// 仅有报错等级,此等级优先级高于规则自身配置
|
|
258
|
+
| SeverityInput
|
|
259
|
+
// 数组情况下,第一项为报错等级,后一项是规则配置
|
|
260
|
+
| [SeverityInput, unknown];
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
如果要**关闭某个规则**,则可以 `SeverityInput` 设为 `off`,如下示例:
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
267
|
+
|
|
268
|
+
export default {
|
|
269
|
+
plugin: [
|
|
270
|
+
new RsdoctorRspackPlugin({
|
|
271
|
+
linter: {
|
|
272
|
+
level: 'Error',
|
|
273
|
+
extends: [],
|
|
274
|
+
rules: {
|
|
275
|
+
'duplicate-package': 'off',
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
}),
|
|
279
|
+
],
|
|
280
|
+
};
|
|
281
|
+
```
|
|
@@ -2,48 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## 功能介绍
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Overall 页面中的 `Alerts` 部分用于展示「构建规则」及「编译规则」结果,如下图。规则展示除了展示在页面中,还会展示在终端日志中。
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
<img src="/bundle-alerts.png" />
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
<img
|
|
11
|
-
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-1.png"
|
|
12
|
-
height="200px"
|
|
13
|
-
width="360px"
|
|
14
|
-
style={{ margin: 'auto' }}
|
|
15
|
-
/>
|
|
16
|
-
<img
|
|
17
|
-
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-2.png"
|
|
18
|
-
height="300px"
|
|
19
|
-
width="440px"
|
|
20
|
-
style={{ margin: 'auto' }}
|
|
21
|
-
/>
|
|
22
|
-
</div>
|
|
9
|
+
可以查看下方的产物预警内置规则了解各个规则详情。
|
|
23
10
|
|
|
24
|
-
|
|
11
|
+
### 内置规则
|
|
25
12
|
|
|
26
|
-
|
|
13
|
+
1. [[E1001] Duplicate Packages](../../guide/rules/rules#e1001-duplicate-packages)
|
|
14
|
+
2. [[E1002] Cross Chunks Package](../../guide/rules/rules#e1002-cross-chunks-package)
|
|
15
|
+
3. [[E1004] ECMA Version Check](../../guide/rules/rules#e1004-ecma-version-check)
|
|
27
16
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- 点击最右侧 **「Show Relations」** 可以查看具体这个第三方的引用链路和对应的引用文件代码位置。
|
|
31
|
-
|
|
32
|
-
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-relations.png" />
|
|
33
|
-
|
|
34
|
-
- 点击最右侧 **「!(叹号)」** 图标,可以查看重复第三方包的规则的具体解释。
|
|
35
|
-
|
|
36
|
-
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alters-rule.png" />
|
|
37
|
-
|
|
38
|
-
### 重复包优化问题
|
|
39
|
-
|
|
40
|
-
请查看[重复包优化方案](../../blog/topic/duplicate-pkg-problem)。
|
|
41
|
-
|
|
42
|
-
### ECMA 版本检查
|
|
43
|
-
|
|
44
|
-
产物预警中会对产物进行 ECMA 版本做检查,如下图:
|
|
45
|
-
|
|
46
|
-
{' '}
|
|
47
|
-
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/bundle/bundle-alerts-ecma.png" />
|
|
48
|
-
|
|
49
|
-
点击 「**More**」可以查看对应规则解释。
|
|
17
|
+
具体可以查看[内置规则](../../guide/rules/rules)。
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
[规则列表](../more/rules)
|
|
15
15
|
:::
|
|
16
16
|
|
|
17
|
-
- `
|
|
18
|
-
- `
|
|
17
|
+
- `E1003` Loader 性能检查。[[E1003] Loader Performance Optimization](/guide/rules/rules#e1003-loader-performance-optimization)
|
|
18
|
+
- `E1005` 默认导入检查。[[E1005] Default Import Check](/guide/rules/rules#e1005-default-import-check)
|
|
@@ -18,97 +18,20 @@
|
|
|
18
18
|
|
|
19
19
|
## 如何使用
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
目前 Rsdoctor 提供**内置规则**和**自定义规则**两种。
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
|
|
23
|
+
### 内置规则
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
plugin: [
|
|
28
|
-
new RsdoctorWebpackPlugin({
|
|
29
|
-
linter: {
|
|
30
|
-
level: 'Error',
|
|
31
|
-
extends: [],
|
|
32
|
-
rules: {
|
|
33
|
-
'default-import-check': 'off',
|
|
34
|
-
'duplicate-package': [
|
|
35
|
-
'Error',
|
|
36
|
-
{
|
|
37
|
-
checkVersion: 'minor',
|
|
38
|
-
ignore: ['chalk', '@babel/runtime'],
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
```
|
|
25
|
+
在现有的诊断器中已经包含了多个规则,默认都已全部开启,它们分别是:
|
|
47
26
|
|
|
48
|
-
|
|
27
|
+
1. [[E1001] Duplicate Packages](/guide/rules/rules#e1001-duplicate-packages)
|
|
28
|
+
2. [[E1002] Cross Chunks Package](/guide/rules/rules#e1002-cross-chunks-package)
|
|
29
|
+
3. [[E1003] Loader Performance Optimization](/guide/rules/rules#e1003-loader-performance-optimization)
|
|
30
|
+
4. [[E1004] ECMA Version Check](/guide/rules/rules#e1004-ecma-version-check)
|
|
31
|
+
5. [[E1005] Default Import Check](/guide/rules/rules#e1005-default-import-check)
|
|
49
32
|
|
|
50
|
-
|
|
33
|
+
具体可以查看[内置规则](/guide/rules/rules)。
|
|
51
34
|
|
|
52
|
-
|
|
53
|
-
import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
|
|
35
|
+
### 自定义规则
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
plugin: [
|
|
57
|
-
new RsdoctorWebpackPlugin({
|
|
58
|
-
linter: {
|
|
59
|
-
rules: {
|
|
60
|
-
'ecma-version-check': [
|
|
61
|
-
'Warn',
|
|
62
|
-
{
|
|
63
|
-
ecmaVersion: 2015,
|
|
64
|
-
// targets: ["chrome >= 53"],
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
更多 `ECMA Version Check` 配置请参考 [ECMA Version Check Options](https://github.com/rspack-contrib/rsbuild-plugin-check-syntax?tab=readme-ov-file#options)
|
|
75
|
-
|
|
76
|
-
`linter`字段的类型为:
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
/** 校验器选项 */
|
|
80
|
-
interface Options {
|
|
81
|
-
rules?: RulesMap;
|
|
82
|
-
level?: SeverityString;
|
|
83
|
-
extends?: ExtendRuleData[];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 校验等级
|
|
88
|
-
* - `'Warn'`时只运行类别为`'Warn'`的规则
|
|
89
|
-
* - `'Error'`时运行全部规则
|
|
90
|
-
*/
|
|
91
|
-
type SeverityString = 'Warn' | 'Error';
|
|
92
|
-
|
|
93
|
-
/** 规则等级 */
|
|
94
|
-
type SeverityInput = SeverityString | 'off' | 'on';
|
|
95
|
-
|
|
96
|
-
/** 规则配置 */
|
|
97
|
-
type RulesMap = Record<string, RuleConfigItem>;
|
|
98
|
-
|
|
99
|
-
/** 单规则配置 */
|
|
100
|
-
type RuleConfigItem =
|
|
101
|
-
// 仅有报错等级,此等级优先级高于规则自身配置
|
|
102
|
-
| SeverityInput
|
|
103
|
-
// 数组情况下,第一项为报错等级,后一项是规则配置
|
|
104
|
-
| [SeverityInput, unknown];
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## 内部已有规则
|
|
108
|
-
|
|
109
|
-
在现有的诊断器中已经包含了三个规则,它们分别是:
|
|
110
|
-
|
|
111
|
-
1. [[E1001] Duplicate Packages](./bundle-alerts#%E9%87%8D%E5%A4%8D%E7%AC%AC%E4%B8%89%E6%96%B9%E5%8C%85)
|
|
112
|
-
2. [[E1002] Default Import Check](../more/rules)
|
|
113
|
-
3. [[E1003] Loader Performance Optimization](../more/rules)
|
|
114
|
-
4. [[E1004] ECMA Version Check](../more/rules)
|
|
37
|
+
Rsdoctor 还会把分析后的数据收集后,用户可以通过 Linter API 接入自定义规则,自定义规则详情查看[自定义规则](/guide/rules/rule-custom)。
|