@meng-xi/vite-plugin 0.1.2 → 0.1.4
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-en.md +86 -510
- package/README.md +83 -506
- package/dist/common/compress/index.cjs +1 -0
- package/dist/common/compress/index.d.cts +23 -0
- package/dist/common/compress/index.d.mts +23 -0
- package/dist/common/compress/index.d.ts +23 -0
- package/dist/common/compress/index.mjs +1 -0
- package/dist/common/format/index.cjs +1 -1
- package/dist/common/format/index.d.cts +33 -1
- package/dist/common/format/index.d.mts +33 -1
- package/dist/common/format/index.d.ts +33 -1
- package/dist/common/format/index.mjs +1 -1
- package/dist/common/fs/index.cjs +1 -1
- package/dist/common/fs/index.d.cts +70 -2
- package/dist/common/fs/index.d.mts +70 -2
- package/dist/common/fs/index.d.ts +70 -2
- package/dist/common/fs/index.mjs +1 -1
- package/dist/common/html/index.cjs +2 -2
- package/dist/common/html/index.d.cts +268 -19
- package/dist/common/html/index.d.mts +268 -19
- package/dist/common/html/index.d.ts +268 -19
- package/dist/common/html/index.mjs +2 -2
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +8 -3
- package/dist/common/index.d.mts +8 -3
- package/dist/common/index.d.ts +8 -3
- package/dist/common/index.mjs +1 -1
- package/dist/common/path/index.cjs +1 -0
- package/dist/common/path/index.d.cts +22 -0
- package/dist/common/path/index.d.mts +22 -0
- package/dist/common/path/index.d.ts +22 -0
- package/dist/common/path/index.mjs +1 -0
- package/dist/common/ui/index.cjs +1 -0
- package/dist/common/ui/index.d.cts +132 -0
- package/dist/common/ui/index.d.mts +132 -0
- package/dist/common/ui/index.d.ts +132 -0
- package/dist/common/ui/index.mjs +1 -0
- package/dist/common/validation/index.cjs +1 -1
- package/dist/common/validation/index.d.cts +1 -0
- package/dist/common/validation/index.d.mts +1 -0
- package/dist/common/validation/index.d.ts +1 -0
- package/dist/common/validation/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +11 -4
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +1 -1
- package/dist/plugins/buildProgress/index.cjs +2 -2
- package/dist/plugins/buildProgress/index.mjs +2 -2
- package/dist/plugins/bundleAnalyzer/index.cjs +235 -0
- package/dist/plugins/bundleAnalyzer/index.d.cts +215 -0
- package/dist/plugins/bundleAnalyzer/index.d.mts +215 -0
- package/dist/plugins/bundleAnalyzer/index.d.ts +215 -0
- package/dist/plugins/bundleAnalyzer/index.mjs +235 -0
- package/dist/plugins/compressAssets/index.cjs +1 -1
- package/dist/plugins/compressAssets/index.mjs +1 -1
- package/dist/plugins/copyFile/index.d.cts +20 -2
- package/dist/plugins/copyFile/index.d.mts +20 -2
- package/dist/plugins/copyFile/index.d.ts +20 -2
- package/dist/plugins/envGuard/index.cjs +67 -0
- package/dist/plugins/envGuard/index.d.cts +156 -0
- package/dist/plugins/envGuard/index.d.mts +156 -0
- package/dist/plugins/envGuard/index.d.ts +156 -0
- package/dist/plugins/envGuard/index.mjs +67 -0
- package/dist/plugins/faviconManager/index.cjs +1 -1
- package/dist/plugins/faviconManager/index.d.cts +43 -5
- package/dist/plugins/faviconManager/index.d.mts +43 -5
- package/dist/plugins/faviconManager/index.d.ts +43 -5
- package/dist/plugins/faviconManager/index.mjs +1 -1
- package/dist/plugins/generateRouter/index.cjs +4 -4
- package/dist/plugins/generateRouter/index.d.cts +61 -14
- package/dist/plugins/generateRouter/index.d.mts +61 -14
- package/dist/plugins/generateRouter/index.d.ts +61 -14
- package/dist/plugins/generateRouter/index.mjs +1 -1
- package/dist/plugins/generateVersion/index.cjs +1 -1
- package/dist/plugins/generateVersion/index.d.cts +12 -0
- package/dist/plugins/generateVersion/index.d.mts +12 -0
- package/dist/plugins/generateVersion/index.d.ts +12 -0
- package/dist/plugins/generateVersion/index.mjs +1 -1
- package/dist/plugins/htmlInject/index.cjs +1 -7
- package/dist/plugins/htmlInject/index.d.cts +49 -194
- package/dist/plugins/htmlInject/index.d.mts +49 -194
- package/dist/plugins/htmlInject/index.d.ts +49 -194
- package/dist/plugins/htmlInject/index.mjs +1 -7
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +5 -1
- package/dist/plugins/index.d.mts +5 -1
- package/dist/plugins/index.d.ts +5 -1
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +2 -2
- package/dist/plugins/loadingManager/index.mjs +1 -1
- package/dist/plugins/versionUpdateChecker/index.cjs +2 -2
- package/dist/plugins/versionUpdateChecker/index.mjs +3 -3
- package/dist/shared/vite-plugin.BCuhU1au.mjs +7 -0
- package/dist/shared/vite-plugin.BrI73DHA.cjs +7 -0
- package/dist/shared/vite-plugin.CmtcnItg.d.cts +261 -0
- package/dist/shared/vite-plugin.CmtcnItg.d.mts +261 -0
- package/dist/shared/vite-plugin.CmtcnItg.d.ts +261 -0
- package/dist/shared/vite-plugin.DnFDPjNf.mjs +1 -0
- package/dist/shared/vite-plugin.Dumot0up.mjs +1 -0
- package/dist/shared/vite-plugin.FfJ-Wwfu.d.cts +143 -0
- package/dist/shared/vite-plugin.FfJ-Wwfu.d.mts +143 -0
- package/dist/shared/vite-plugin.FfJ-Wwfu.d.ts +143 -0
- package/dist/shared/vite-plugin.soT9a-KD.cjs +1 -0
- package/dist/shared/vite-plugin.vwox4bU0.cjs +1 -0
- package/package.json +26 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { BasePluginOptions, PluginFactory } from '../../factory/index.mjs';
|
|
2
|
+
import 'vite';
|
|
3
|
+
import '../../shared/vite-plugin.CLr0ttuO.mjs';
|
|
4
|
+
import '../../shared/vite-plugin.DRRlWY8P.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 输出报告格式类型
|
|
8
|
+
*
|
|
9
|
+
* @typedef {('json' | 'html' | 'both')} BundleOutputFormat
|
|
10
|
+
* @description 支持的报告输出格式:
|
|
11
|
+
* - `json`: 生成 JSON 格式的分析报告
|
|
12
|
+
* - `html`: 生成包含可视化图表的 HTML 报告
|
|
13
|
+
* - `both`: 同时生成 JSON 和 HTML 报告
|
|
14
|
+
*/
|
|
15
|
+
type BundleOutputFormat = 'json' | 'html' | 'both';
|
|
16
|
+
/**
|
|
17
|
+
* 单个模块的统计信息
|
|
18
|
+
*
|
|
19
|
+
* @interface ModuleStats
|
|
20
|
+
* @description 记录构建产物中单个模块的详细统计数据
|
|
21
|
+
*/
|
|
22
|
+
interface ModuleStats {
|
|
23
|
+
/** 模块标识符(通常是模块路径或 ID) */
|
|
24
|
+
id: string;
|
|
25
|
+
/** 模块原始大小(字节) */
|
|
26
|
+
size: number;
|
|
27
|
+
/** 模块 gzip 压缩后大小(字节),仅在 gzipSize 开启时可用 */
|
|
28
|
+
gzipSize: number;
|
|
29
|
+
/** 所属 chunk 名称列表 */
|
|
30
|
+
chunks: string[];
|
|
31
|
+
/** 该模块的依赖模块 ID 列表 */
|
|
32
|
+
imports: string[];
|
|
33
|
+
/** 是否为入口模块 */
|
|
34
|
+
isEntry: boolean;
|
|
35
|
+
/** 是否来自 node_modules */
|
|
36
|
+
isNodeModule: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 单个 chunk 的统计信息
|
|
40
|
+
*
|
|
41
|
+
* @interface ChunkStats
|
|
42
|
+
* @description 记录构建产物中单个 chunk 的详细统计数据
|
|
43
|
+
*/
|
|
44
|
+
interface ChunkStats {
|
|
45
|
+
/** chunk 名称 */
|
|
46
|
+
name: string;
|
|
47
|
+
/** chunk 原始大小(字节) */
|
|
48
|
+
size: number;
|
|
49
|
+
/** chunk gzip 压缩后大小(字节),仅在 gzipSize 开启时可用 */
|
|
50
|
+
gzipSize: number;
|
|
51
|
+
/** chunk 包含的模块列表 */
|
|
52
|
+
modules: ModuleStats[];
|
|
53
|
+
/** chunk 类型标识(如 'entry'、'chunk'、'asset') */
|
|
54
|
+
type: 'entry' | 'chunk' | 'asset';
|
|
55
|
+
/** chunk 包含的文件数量 */
|
|
56
|
+
fileCount: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 文件类型分布统计项
|
|
60
|
+
*
|
|
61
|
+
* @interface FileTypeDistribution
|
|
62
|
+
* @description 按文件扩展名分类的体积分布统计
|
|
63
|
+
*/
|
|
64
|
+
interface FileTypeDistribution {
|
|
65
|
+
/** 文件扩展名(如 '.js', '.css') */
|
|
66
|
+
extension: string;
|
|
67
|
+
/** 该类型的文件数量 */
|
|
68
|
+
count: number;
|
|
69
|
+
/** 该类型的总大小(字节) */
|
|
70
|
+
totalSize: number;
|
|
71
|
+
/** 该类型的总体积占比(0-100) */
|
|
72
|
+
percentage: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 体积阈值告警信息
|
|
76
|
+
*
|
|
77
|
+
* @interface SizeWarning
|
|
78
|
+
* @description 当模块或 chunk 超过配置的体积阈值时生成的告警
|
|
79
|
+
*/
|
|
80
|
+
interface SizeWarning {
|
|
81
|
+
/** 告警类型:模块级别或 chunk 级别 */
|
|
82
|
+
level: 'module' | 'chunk';
|
|
83
|
+
/** 告警目标名称 */
|
|
84
|
+
name: string;
|
|
85
|
+
/** 实际大小(KB) */
|
|
86
|
+
sizeKB: number;
|
|
87
|
+
/** 阈值大小(KB) */
|
|
88
|
+
thresholdKB: number;
|
|
89
|
+
/** 告警消息 */
|
|
90
|
+
message: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 构建对比差异项
|
|
94
|
+
*
|
|
95
|
+
* @interface ComparisonDiff
|
|
96
|
+
* @description 两次构建之间同一模块/chunk 的体积变化
|
|
97
|
+
*/
|
|
98
|
+
interface ComparisonDiff {
|
|
99
|
+
/** 模块或 chunk 名称 */
|
|
100
|
+
name: string;
|
|
101
|
+
/** 上次构建大小(字节),不存在则为 -1 */
|
|
102
|
+
previousSize: number;
|
|
103
|
+
/** 本次构建大小(字节) */
|
|
104
|
+
currentSize: number;
|
|
105
|
+
/** 体积变化量(字节),正数表示增大 */
|
|
106
|
+
diff: number;
|
|
107
|
+
/** 变化百分比 */
|
|
108
|
+
diffPercentage: number;
|
|
109
|
+
/** 变化趋势:增大、减小、不变、新增、移除 */
|
|
110
|
+
trend: 'increased' | 'decreased' | 'unchanged' | 'added' | 'removed';
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 构建产物分析结果
|
|
114
|
+
*
|
|
115
|
+
* @interface BundleAnalysisResult
|
|
116
|
+
* @description 包含完整的构建产物分析数据,用于报告生成和日志输出
|
|
117
|
+
*/
|
|
118
|
+
interface BundleAnalysisResult {
|
|
119
|
+
/** 分析时间戳(ISO 格式) */
|
|
120
|
+
timestamp: string;
|
|
121
|
+
/** 构建产物总大小(字节) */
|
|
122
|
+
totalSize: number;
|
|
123
|
+
/** 构建产物 gzip 总大小(字节) */
|
|
124
|
+
totalGzipSize: number;
|
|
125
|
+
/** chunk 统计列表 */
|
|
126
|
+
chunks: ChunkStats[];
|
|
127
|
+
/** Top N 大模块排行 */
|
|
128
|
+
topModules: ModuleStats[];
|
|
129
|
+
/** 文件类型分布统计 */
|
|
130
|
+
fileTypeDistribution: FileTypeDistribution[];
|
|
131
|
+
/** 体积阈值告警列表 */
|
|
132
|
+
warnings: SizeWarning[];
|
|
133
|
+
/** 构建对比差异列表(仅在配置 compareWith 时可用) */
|
|
134
|
+
comparisonDiffs: ComparisonDiff[];
|
|
135
|
+
/** 分析耗时(毫秒) */
|
|
136
|
+
analysisTime: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 构建产物分析插件的配置选项
|
|
140
|
+
*
|
|
141
|
+
* @interface BundleAnalyzerOptions
|
|
142
|
+
* @extends {BasePluginOptions}
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* bundleAnalyzer({
|
|
147
|
+
* outputFormat: 'both',
|
|
148
|
+
* outputFile: 'bundle-analysis',
|
|
149
|
+
* openAnalyzer: true,
|
|
150
|
+
* sizeThreshold: 200,
|
|
151
|
+
* topModules: 30,
|
|
152
|
+
* gzipSize: true,
|
|
153
|
+
* compareWith: 'bundle-analysis-prev.json'
|
|
154
|
+
* })
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
interface BundleAnalyzerOptions extends BasePluginOptions {
|
|
158
|
+
/** 报告输出格式:json、html 或同时输出两者 */
|
|
159
|
+
outputFormat?: BundleOutputFormat;
|
|
160
|
+
/** 报告输出文件名(不含扩展名),默认 'bundle-analysis' */
|
|
161
|
+
outputFile?: string;
|
|
162
|
+
/** 是否在生成 HTML 报告后自动打开浏览器 */
|
|
163
|
+
openAnalyzer?: boolean;
|
|
164
|
+
/** 体积告警阈值(KB),超过此大小的 chunk 将产生告警 */
|
|
165
|
+
sizeThreshold?: number;
|
|
166
|
+
/** Top N 大模块排行数量 */
|
|
167
|
+
topModules?: number;
|
|
168
|
+
/** 用于对比的之前分析报告路径,设为 null 则不进行对比 */
|
|
169
|
+
compareWith?: string | null;
|
|
170
|
+
/** 是否计算 gzip 大小 */
|
|
171
|
+
gzipSize?: boolean;
|
|
172
|
+
/** 是否在分析中排除 node_modules 中的模块 */
|
|
173
|
+
excludeNodeModules?: boolean;
|
|
174
|
+
/** 需要排除的文件路径模式列表(支持 glob 模式) */
|
|
175
|
+
excludePatterns?: string[];
|
|
176
|
+
/** 需要包含的文件扩展名列表,为空则包含所有 */
|
|
177
|
+
includeExtensions?: string[];
|
|
178
|
+
/** HTML 报告中图表的默认展示形式 */
|
|
179
|
+
defaultChartType?: 'treemap' | 'sunburst' | 'list';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 创建构建产物分析插件
|
|
184
|
+
*
|
|
185
|
+
* @function bundleAnalyzer
|
|
186
|
+
* @param {Partial<BundleAnalyzerOptions>} [options] - 插件配置选项
|
|
187
|
+
* @returns {Plugin} Vite 插件实例
|
|
188
|
+
*
|
|
189
|
+
* @description 在 Vite 构建完成后自动分析输出目录中的构建产物,
|
|
190
|
+
* 生成体积统计、模块排行、文件类型分布等关键指标,
|
|
191
|
+
* 支持 JSON 报告和 HTML 可视化图表,支持体积阈值告警和构建对比。
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* // vite.config.ts
|
|
196
|
+
* import { bundleAnalyzer } from '@meng-xi/vite-plugin'
|
|
197
|
+
*
|
|
198
|
+
* export default defineConfig({
|
|
199
|
+
* plugins: [
|
|
200
|
+
* bundleAnalyzer({
|
|
201
|
+
* outputFormat: 'both',
|
|
202
|
+
* sizeThreshold: 200,
|
|
203
|
+
* topModules: 30,
|
|
204
|
+
* gzipSize: true,
|
|
205
|
+
* compareWith: 'bundle-analysis-prev.json',
|
|
206
|
+
* defaultChartType: 'treemap'
|
|
207
|
+
* })
|
|
208
|
+
* ]
|
|
209
|
+
* })
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
declare const bundleAnalyzer: PluginFactory<BundleAnalyzerOptions, BundleAnalyzerOptions>;
|
|
213
|
+
|
|
214
|
+
export { bundleAnalyzer };
|
|
215
|
+
export type { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { BasePluginOptions, PluginFactory } from '../../factory/index.js';
|
|
2
|
+
import 'vite';
|
|
3
|
+
import '../../shared/vite-plugin.CLr0ttuO.js';
|
|
4
|
+
import '../../shared/vite-plugin.DRRlWY8P.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 输出报告格式类型
|
|
8
|
+
*
|
|
9
|
+
* @typedef {('json' | 'html' | 'both')} BundleOutputFormat
|
|
10
|
+
* @description 支持的报告输出格式:
|
|
11
|
+
* - `json`: 生成 JSON 格式的分析报告
|
|
12
|
+
* - `html`: 生成包含可视化图表的 HTML 报告
|
|
13
|
+
* - `both`: 同时生成 JSON 和 HTML 报告
|
|
14
|
+
*/
|
|
15
|
+
type BundleOutputFormat = 'json' | 'html' | 'both';
|
|
16
|
+
/**
|
|
17
|
+
* 单个模块的统计信息
|
|
18
|
+
*
|
|
19
|
+
* @interface ModuleStats
|
|
20
|
+
* @description 记录构建产物中单个模块的详细统计数据
|
|
21
|
+
*/
|
|
22
|
+
interface ModuleStats {
|
|
23
|
+
/** 模块标识符(通常是模块路径或 ID) */
|
|
24
|
+
id: string;
|
|
25
|
+
/** 模块原始大小(字节) */
|
|
26
|
+
size: number;
|
|
27
|
+
/** 模块 gzip 压缩后大小(字节),仅在 gzipSize 开启时可用 */
|
|
28
|
+
gzipSize: number;
|
|
29
|
+
/** 所属 chunk 名称列表 */
|
|
30
|
+
chunks: string[];
|
|
31
|
+
/** 该模块的依赖模块 ID 列表 */
|
|
32
|
+
imports: string[];
|
|
33
|
+
/** 是否为入口模块 */
|
|
34
|
+
isEntry: boolean;
|
|
35
|
+
/** 是否来自 node_modules */
|
|
36
|
+
isNodeModule: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 单个 chunk 的统计信息
|
|
40
|
+
*
|
|
41
|
+
* @interface ChunkStats
|
|
42
|
+
* @description 记录构建产物中单个 chunk 的详细统计数据
|
|
43
|
+
*/
|
|
44
|
+
interface ChunkStats {
|
|
45
|
+
/** chunk 名称 */
|
|
46
|
+
name: string;
|
|
47
|
+
/** chunk 原始大小(字节) */
|
|
48
|
+
size: number;
|
|
49
|
+
/** chunk gzip 压缩后大小(字节),仅在 gzipSize 开启时可用 */
|
|
50
|
+
gzipSize: number;
|
|
51
|
+
/** chunk 包含的模块列表 */
|
|
52
|
+
modules: ModuleStats[];
|
|
53
|
+
/** chunk 类型标识(如 'entry'、'chunk'、'asset') */
|
|
54
|
+
type: 'entry' | 'chunk' | 'asset';
|
|
55
|
+
/** chunk 包含的文件数量 */
|
|
56
|
+
fileCount: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 文件类型分布统计项
|
|
60
|
+
*
|
|
61
|
+
* @interface FileTypeDistribution
|
|
62
|
+
* @description 按文件扩展名分类的体积分布统计
|
|
63
|
+
*/
|
|
64
|
+
interface FileTypeDistribution {
|
|
65
|
+
/** 文件扩展名(如 '.js', '.css') */
|
|
66
|
+
extension: string;
|
|
67
|
+
/** 该类型的文件数量 */
|
|
68
|
+
count: number;
|
|
69
|
+
/** 该类型的总大小(字节) */
|
|
70
|
+
totalSize: number;
|
|
71
|
+
/** 该类型的总体积占比(0-100) */
|
|
72
|
+
percentage: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 体积阈值告警信息
|
|
76
|
+
*
|
|
77
|
+
* @interface SizeWarning
|
|
78
|
+
* @description 当模块或 chunk 超过配置的体积阈值时生成的告警
|
|
79
|
+
*/
|
|
80
|
+
interface SizeWarning {
|
|
81
|
+
/** 告警类型:模块级别或 chunk 级别 */
|
|
82
|
+
level: 'module' | 'chunk';
|
|
83
|
+
/** 告警目标名称 */
|
|
84
|
+
name: string;
|
|
85
|
+
/** 实际大小(KB) */
|
|
86
|
+
sizeKB: number;
|
|
87
|
+
/** 阈值大小(KB) */
|
|
88
|
+
thresholdKB: number;
|
|
89
|
+
/** 告警消息 */
|
|
90
|
+
message: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 构建对比差异项
|
|
94
|
+
*
|
|
95
|
+
* @interface ComparisonDiff
|
|
96
|
+
* @description 两次构建之间同一模块/chunk 的体积变化
|
|
97
|
+
*/
|
|
98
|
+
interface ComparisonDiff {
|
|
99
|
+
/** 模块或 chunk 名称 */
|
|
100
|
+
name: string;
|
|
101
|
+
/** 上次构建大小(字节),不存在则为 -1 */
|
|
102
|
+
previousSize: number;
|
|
103
|
+
/** 本次构建大小(字节) */
|
|
104
|
+
currentSize: number;
|
|
105
|
+
/** 体积变化量(字节),正数表示增大 */
|
|
106
|
+
diff: number;
|
|
107
|
+
/** 变化百分比 */
|
|
108
|
+
diffPercentage: number;
|
|
109
|
+
/** 变化趋势:增大、减小、不变、新增、移除 */
|
|
110
|
+
trend: 'increased' | 'decreased' | 'unchanged' | 'added' | 'removed';
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 构建产物分析结果
|
|
114
|
+
*
|
|
115
|
+
* @interface BundleAnalysisResult
|
|
116
|
+
* @description 包含完整的构建产物分析数据,用于报告生成和日志输出
|
|
117
|
+
*/
|
|
118
|
+
interface BundleAnalysisResult {
|
|
119
|
+
/** 分析时间戳(ISO 格式) */
|
|
120
|
+
timestamp: string;
|
|
121
|
+
/** 构建产物总大小(字节) */
|
|
122
|
+
totalSize: number;
|
|
123
|
+
/** 构建产物 gzip 总大小(字节) */
|
|
124
|
+
totalGzipSize: number;
|
|
125
|
+
/** chunk 统计列表 */
|
|
126
|
+
chunks: ChunkStats[];
|
|
127
|
+
/** Top N 大模块排行 */
|
|
128
|
+
topModules: ModuleStats[];
|
|
129
|
+
/** 文件类型分布统计 */
|
|
130
|
+
fileTypeDistribution: FileTypeDistribution[];
|
|
131
|
+
/** 体积阈值告警列表 */
|
|
132
|
+
warnings: SizeWarning[];
|
|
133
|
+
/** 构建对比差异列表(仅在配置 compareWith 时可用) */
|
|
134
|
+
comparisonDiffs: ComparisonDiff[];
|
|
135
|
+
/** 分析耗时(毫秒) */
|
|
136
|
+
analysisTime: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 构建产物分析插件的配置选项
|
|
140
|
+
*
|
|
141
|
+
* @interface BundleAnalyzerOptions
|
|
142
|
+
* @extends {BasePluginOptions}
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* bundleAnalyzer({
|
|
147
|
+
* outputFormat: 'both',
|
|
148
|
+
* outputFile: 'bundle-analysis',
|
|
149
|
+
* openAnalyzer: true,
|
|
150
|
+
* sizeThreshold: 200,
|
|
151
|
+
* topModules: 30,
|
|
152
|
+
* gzipSize: true,
|
|
153
|
+
* compareWith: 'bundle-analysis-prev.json'
|
|
154
|
+
* })
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
interface BundleAnalyzerOptions extends BasePluginOptions {
|
|
158
|
+
/** 报告输出格式:json、html 或同时输出两者 */
|
|
159
|
+
outputFormat?: BundleOutputFormat;
|
|
160
|
+
/** 报告输出文件名(不含扩展名),默认 'bundle-analysis' */
|
|
161
|
+
outputFile?: string;
|
|
162
|
+
/** 是否在生成 HTML 报告后自动打开浏览器 */
|
|
163
|
+
openAnalyzer?: boolean;
|
|
164
|
+
/** 体积告警阈值(KB),超过此大小的 chunk 将产生告警 */
|
|
165
|
+
sizeThreshold?: number;
|
|
166
|
+
/** Top N 大模块排行数量 */
|
|
167
|
+
topModules?: number;
|
|
168
|
+
/** 用于对比的之前分析报告路径,设为 null 则不进行对比 */
|
|
169
|
+
compareWith?: string | null;
|
|
170
|
+
/** 是否计算 gzip 大小 */
|
|
171
|
+
gzipSize?: boolean;
|
|
172
|
+
/** 是否在分析中排除 node_modules 中的模块 */
|
|
173
|
+
excludeNodeModules?: boolean;
|
|
174
|
+
/** 需要排除的文件路径模式列表(支持 glob 模式) */
|
|
175
|
+
excludePatterns?: string[];
|
|
176
|
+
/** 需要包含的文件扩展名列表,为空则包含所有 */
|
|
177
|
+
includeExtensions?: string[];
|
|
178
|
+
/** HTML 报告中图表的默认展示形式 */
|
|
179
|
+
defaultChartType?: 'treemap' | 'sunburst' | 'list';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 创建构建产物分析插件
|
|
184
|
+
*
|
|
185
|
+
* @function bundleAnalyzer
|
|
186
|
+
* @param {Partial<BundleAnalyzerOptions>} [options] - 插件配置选项
|
|
187
|
+
* @returns {Plugin} Vite 插件实例
|
|
188
|
+
*
|
|
189
|
+
* @description 在 Vite 构建完成后自动分析输出目录中的构建产物,
|
|
190
|
+
* 生成体积统计、模块排行、文件类型分布等关键指标,
|
|
191
|
+
* 支持 JSON 报告和 HTML 可视化图表,支持体积阈值告警和构建对比。
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* // vite.config.ts
|
|
196
|
+
* import { bundleAnalyzer } from '@meng-xi/vite-plugin'
|
|
197
|
+
*
|
|
198
|
+
* export default defineConfig({
|
|
199
|
+
* plugins: [
|
|
200
|
+
* bundleAnalyzer({
|
|
201
|
+
* outputFormat: 'both',
|
|
202
|
+
* sizeThreshold: 200,
|
|
203
|
+
* topModules: 30,
|
|
204
|
+
* gzipSize: true,
|
|
205
|
+
* compareWith: 'bundle-analysis-prev.json',
|
|
206
|
+
* defaultChartType: 'treemap'
|
|
207
|
+
* })
|
|
208
|
+
* ]
|
|
209
|
+
* })
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
declare const bundleAnalyzer: PluginFactory<BundleAnalyzerOptions, BundleAnalyzerOptions>;
|
|
213
|
+
|
|
214
|
+
export { bundleAnalyzer };
|
|
215
|
+
export type { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning };
|