Skip to content

Commit 4f7bc53

Browse files
committed
Refactor project to create @winner-fed/plugin-rsdoctor, integrating Rsdoctor for build analysis and performance optimization. Update dependencies, enhance README with usage instructions, and configure playground for testing.
1 parent c7265fb commit 4f7bc53

File tree

8 files changed

+2684
-1278
lines changed

8 files changed

+2684
-1278
lines changed

README.md

Lines changed: 465 additions & 23 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "winjs-plugin-template",
2+
"name": "@winner-fed/plugin-rsdoctor",
3+
"description": "WinJS plugin for Rsdoctor - Build analysis and performance optimization tool",
34
"keywords": [
45
"winjs",
56
"plugin",
6-
"template",
7+
"rsdoctor",
78
"winner-fed",
89
"winjs-dev",
9-
"rslib",
10-
"rsbuild",
11-
"typescript",
12-
"biome"
10+
"rspack",
11+
"build-analysis",
12+
"performance"
1313
],
14-
"version": "0.0.0",
14+
"version": "0.0.1",
1515
"repository": {
1616
"type": "git",
17-
"url": "git+https://github.com/winjs-dev/winjs-plugin-template.git"
17+
"url": "git+https://github.com/winjs-dev/winjs-plugin-rsdoctor.git"
1818
},
1919
"license": "MIT",
2020
"type": "module",
@@ -58,14 +58,22 @@
5858
"@winner-fed/winjs": "*"
5959
},
6060
"peerDependencies": {
61-
"@winner-fed/utils": "*"
61+
"@winner-fed/utils": "*",
62+
"@rsdoctor/rspack-plugin": "^1.3.6",
63+
"@rsdoctor/webpack-plugin": "^1.3.6"
6264
},
6365
"peerDependenciesMeta": {
6466
"@rsbuild/core": {
6567
"optional": true
6668
},
6769
"@winner-fed/utils": {
6870
"optional": true
71+
},
72+
"@rsdoctor/rspack-plugin": {
73+
"optional": true
74+
},
75+
"@rsdoctor/webpack-plugin": {
76+
"optional": true
6977
}
7078
},
7179
"publishConfig": {

playground/.winrc.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { defineConfig } from 'win';
1+
import { defineConfig } from '@winner-fed/winjs';
22

33
export default defineConfig({
4-
plugins: ['../src'],
5-
example: {
6-
foo: 'bar',
4+
plugins: ['../dist'],
5+
presets: ['@winner-fed/preset-vue'],
6+
// rsbuild: {},
7+
vite: {},
8+
rsdoctor: {
9+
disableClientServer: false
710
},
811
});

playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@winner-fed/winjs": "*"
1515
},
1616
"devDependencies": {
17-
"typescript": "^5.0.3"
17+
"typescript": "^5.0.3",
18+
"@winner-fed/preset-vue": "*"
1819
}
1920
}

playground/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IApi } from 'win';
1+
import type { IApi } from '@winner-fed/winjs';
22

33
export default (api: IApi) => {
44
api.modifyHTML(($) => {

pnpm-lock.yaml

Lines changed: 1795 additions & 1233 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 250 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,263 @@
1+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
2+
import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
13
import type { IApi } from '@winner-fed/winjs';
24

5+
export type {
6+
LinterLevel,
7+
RsdoctorConfig,
8+
RsdoctorFeatures,
9+
RsdoctorHtmlOptions,
10+
RsdoctorJsonOptions,
11+
RsdoctorJsonSections,
12+
RsdoctorLinter,
13+
RsdoctorMode,
14+
RsdoctorOptions,
15+
RsdoctorOutputOptions,
16+
RsdoctorOutputType,
17+
RsdoctorReportCodeType,
18+
RsdoctorReportOptions,
19+
RsdoctorSupports,
20+
} from './types.js';
21+
322
export default (api: IApi) => {
423
api.describe({
5-
key: 'example',
24+
key: 'rsdoctor',
625
enableBy: api.EnableBy.config,
726
config: {
8-
schema({ zod }) {
9-
return zod.object({
10-
foo: zod.string(),
11-
});
27+
// biome-ignore lint/suspicious/noExplicitAny: zod 参数来自 winjs API
28+
schema({ zod }: any) {
29+
return zod
30+
.union([
31+
// 支持简单的布尔值启用/禁用
32+
zod
33+
.boolean()
34+
.describe('是否启用 Rsdoctor 构建分析工具'),
35+
// 支持详细配置对象
36+
zod.object({
37+
// 是否禁用客户端服务器(不自动打开浏览器)
38+
disableClientServer: zod
39+
.boolean()
40+
.optional()
41+
.describe(
42+
'是否禁用客户端服务器。设置为 true 时,构建完成后不会自动打开浏览器展示分析报告',
43+
),
44+
45+
// 报告模式:brief-简要、normal-正常
46+
mode: zod
47+
.enum(['brief', 'normal'])
48+
.optional()
49+
.describe(
50+
'报告模式(V1.2.4 新增)。brief: 在构建产物目录中生成单个 HTML 报告文件;normal: 在构建产物目录中生成 .rsdoctor 文件夹,包含各种数据文件并在报告页面中展示代码。默认为 normal',
51+
),
52+
53+
// 分析特性配置
54+
features: zod
55+
.object({
56+
loader: zod
57+
.boolean()
58+
.optional()
59+
.describe(
60+
'是否启用 Loader 分析,用于分析各个 loader 的执行时间和输入输出',
61+
),
62+
plugins: zod
63+
.boolean()
64+
.optional()
65+
.describe('是否启用插件分析,用于分析各个插件的执行时间'),
66+
resolver: zod
67+
.boolean()
68+
.optional()
69+
.describe('是否启用解析器分析,用于分析模块解析过程和性能'),
70+
bundle: zod
71+
.boolean()
72+
.optional()
73+
.describe(
74+
'是否启用产物分析,用于分析最终产物的体积、重复依赖等',
75+
),
76+
treeShaking: zod
77+
.boolean()
78+
.optional()
79+
.describe(
80+
'是否启用 Tree Shaking 分析,用于检测未使用的代码',
81+
),
82+
})
83+
.optional()
84+
.describe('分析特性配置,可以选择性启用需要的分析功能'),
85+
86+
// Linter 规则配置
87+
linter: zod
88+
.object({
89+
level: zod
90+
.enum(['off', 'warn', 'error'])
91+
.optional()
92+
.describe(
93+
'Linter 规则级别。off: 关闭;warn: 警告;error: 错误',
94+
),
95+
extends: zod
96+
.array(zod.any())
97+
.optional()
98+
.describe('扩展的 Linter 规则集数组'),
99+
rules: zod
100+
.record(zod.any())
101+
.optional()
102+
.describe('自定义 Linter 规则对象'),
103+
})
104+
.optional()
105+
.describe('Linter 规则配置,用于检测构建过程中的潜在问题'),
106+
107+
// 其他支持特性
108+
supports: zod
109+
.object({
110+
generateTileGraph: zod
111+
.boolean()
112+
.optional()
113+
.describe('是否生成平铺图,用于可视化模块之间的依赖关系'),
114+
})
115+
.optional()
116+
.describe('其他支持特性配置'),
117+
118+
// 分析报告输出配置
119+
output: zod
120+
.object({
121+
mode: zod
122+
.enum(['brief', 'normal'])
123+
.optional()
124+
.describe(
125+
'brief: 用于生成轻量级的分析报告,支持 HTML 和 JSON 两种输出格式;normal: 在构建产物目录中生成 .rsdoctor 文件夹,包含各种数据文件。默认为 normal',
126+
),
127+
reportCodeType: zod
128+
.object({
129+
noModuleSource: zod
130+
.boolean()
131+
.optional()
132+
.describe(
133+
'输出除模块(Module)代码外的数据,模块(Module)代码即产物((Module))内各个文件的打包模块代码',
134+
),
135+
noAssetsAndModuleSource: zod
136+
.boolean()
137+
.optional()
138+
.describe(
139+
'输出除模块(Module)代码和 Assets 产物代码外的数据',
140+
),
141+
})
142+
.optional()
143+
.describe('选择输出的分析数据范围,用于控制输出数据的大小'),
144+
reportDir: zod
145+
.string()
146+
.optional()
147+
.describe('Rsdoctor 报告输出目录,默认是构建产物输出目录'),
148+
options: zod
149+
.object({
150+
type: zod
151+
.array(zod.enum(['html', 'json']))
152+
.optional()
153+
.describe(
154+
'输出类型,支持 html 和 json 数组,可同时选择多种格式。如 ["html", "json"] 会同时生成 html 和 json 文件',
155+
),
156+
htmlOptions: zod
157+
.object({
158+
reportHtmlName: zod
159+
.string()
160+
.optional()
161+
.describe(
162+
'HTML 报告文件名,默认为 report-rsdoctor.html',
163+
),
164+
})
165+
.optional()
166+
.describe('HTML 输出相关配置'),
167+
jsonOptions: zod
168+
.object({
169+
sections: zod
170+
.object({
171+
moduleGraph: zod
172+
.boolean()
173+
.optional()
174+
.describe('是否包含模块图数据,默认为 true'),
175+
chunkGraph: zod
176+
.boolean()
177+
.optional()
178+
.describe('是否包含 Chunk 图数据,默认为 true'),
179+
rules: zod
180+
.boolean()
181+
.optional()
182+
.describe('是否包含规则数据,默认为 true'),
183+
})
184+
.optional()
185+
.describe('JSON 输出包含的模块配置'),
186+
})
187+
.optional()
188+
.describe('JSON 输出相关配置'),
189+
compressData: zod
190+
.boolean()
191+
.optional()
192+
.describe(
193+
'是否压缩分析数据,启用后可以减小报告文件大小',
194+
),
195+
})
196+
.optional()
197+
.describe(
198+
'分析报告输出选项配置,包含 type、htmlOptions、jsonOptions、compressData 等',
199+
),
200+
})
201+
.optional()
202+
.describe(
203+
'分析报告输出配置对象,包含 mode、reportCodeType、reportDir、options 等选项',
204+
),
205+
206+
// Rsdoctor 分析服务器端口号
207+
port: zod
208+
.number()
209+
.optional()
210+
.describe(
211+
'Rsdoctor 分析服务器的端口号。当启用客户端服务器时,会在此端口启动本地服务展示分析报告。默认值: 8791',
212+
),
213+
}),
214+
])
215+
.describe(
216+
'Rsdoctor 构建分析工具配置。可以传入布尔值快速启用,或传入配置对象进行详细配置',
217+
);
12218
},
13219
},
14220
});
15221

16-
api.modifyConfig((memo) => {
17-
memo.foo = api.userConfig.example.foo;
222+
// Vite 模式下不支持
223+
if (api.userConfig.vite) {
224+
api.logger.warn(
225+
'[rsdoctor] Rsdoctor 不支持 Vite 模式,请使用 Webpack 或 Rsbuild',
226+
);
227+
return;
228+
}
229+
230+
// Rsbuild 模式使用自带功能
231+
if (api.userConfig.rsbuild) {
232+
api.modifyRspackConfig((memo) => {
233+
const cfg = api.userConfig.rsdoctor;
234+
if (!cfg) return memo;
235+
236+
const opts =
237+
typeof cfg === 'boolean' ? { port: 8791 } : { port: 8791, ...cfg };
238+
239+
memo.plugins ||= [];
240+
memo.plugins.push(new RsdoctorRspackPlugin(opts));
241+
242+
api.logger.info('[plugin-rsdoctor] 已启用 Rsbuild 内置 Rsdoctor 功能');
243+
return memo;
244+
});
245+
return;
246+
}
247+
248+
// Webpack 模式
249+
api.modifyWebpackConfig((memo) => {
250+
const cfg = api.userConfig.rsdoctor;
251+
if (!cfg) return memo;
252+
253+
const opts =
254+
typeof cfg === 'boolean' ? { port: 8791 } : { port: 8791, ...cfg };
255+
256+
memo.plugins = (memo.plugins || []).concat([
257+
new RsdoctorWebpackPlugin(opts),
258+
]);
259+
260+
api.logger.info('[plugin-rsdoctor] 已启用 Webpack Rsdoctor 插件');
18261
return memo;
19262
});
20263
};

0 commit comments

Comments
 (0)