@meng-xi/vite-plugin 0.0.6 → 0.0.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.
package/README.md CHANGED
@@ -15,8 +15,8 @@
15
15
 
16
16
  ## 特性
17
17
 
18
- - **开箱即用** - 提供文件复制、路由生成、版本管理、图标注入等实用插件
19
- - **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义插件
18
+ - **开箱即用** - 提供 buildProgress、copyFile、generateRouter、generateVersion、injectIco 五个实用插件,覆盖构建进度展示、文件复制、路由生成、版本管理、图标注入等常见场景
19
+ - **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建符合规范的自定义 Vite 插件
20
20
  - **完整生命周期** - 支持初始化、配置解析、销毁等生命周期管理,自动组合钩子逻辑
21
21
  - **类型安全** - 完整的 TypeScript 类型定义,配置验证器确保参数正确性
22
22
  - **灵活配置** - 所有插件支持详细配置,满足多样化场景需求
@@ -28,27 +28,35 @@
28
28
 
29
29
  ## 安装
30
30
 
31
- ```bash
32
- # npm
31
+ ::: code-group
32
+
33
+ ```bash [npm]
33
34
  npm install @meng-xi/vite-plugin -D
35
+ ```
34
36
 
35
- # yarn
37
+ ```bash [yarn]
36
38
  yarn add @meng-xi/vite-plugin -D
39
+ ```
37
40
 
38
- # pnpm
41
+ ```bash [pnpm]
39
42
  pnpm add @meng-xi/vite-plugin -D
40
43
  ```
41
44
 
45
+ :::
46
+
42
47
  ## 快速开始
43
48
 
44
49
  ### 使用内置插件
45
50
 
46
51
  ```typescript
47
52
  import { defineConfig } from 'vite'
48
- import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
53
+ import { buildProgress, copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
49
54
 
50
55
  export default defineConfig({
51
56
  plugins: [
57
+ // 构建进度条
58
+ buildProgress(),
59
+
52
60
  // 复制文件
53
61
  copyFile({
54
62
  sourceDir: 'src/assets',
@@ -196,7 +204,7 @@ const result = await this.safeExecute(async () => {
196
204
 
197
205
  ### createPluginFactory
198
206
 
199
- 创建插件工厂函数,支持选项标准化:
207
+ 创建插件工厂函数,支持选项标准化器:
200
208
 
201
209
  ```typescript
202
210
  // 基本使用
@@ -237,6 +245,49 @@ Logger.destroy()
237
245
 
238
246
  ## 内置插件
239
247
 
248
+ ### buildProgress
249
+
250
+ 在终端实时显示 Vite 构建进度条,支持三种显示格式。
251
+
252
+ | 选项 | 类型 | 默认值 | 描述 |
253
+ | --------------- | ------------------------------------- | ------ | ------------------------------ |
254
+ | width | number | 30 | 进度条宽度(字符数) |
255
+ | format | `'bar'` \| `'spinner'` \| `'minimal'` | 'bar' | 进度条显示格式 |
256
+ | completeChar | string | '█' | 已完成部分的填充字符 |
257
+ | incompleteChar | string | '░' | 未完成部分的填充字符 |
258
+ | clearOnComplete | boolean | true | 构建完成后是否清除进度条 |
259
+ | showModuleName | boolean | true | 是否显示当前正在处理的模块名称 |
260
+ | theme | [ProgressTheme](#progresstheme) | - | 自定义颜色主题 |
261
+
262
+ **ProgressTheme**
263
+
264
+ | 属性 | 类型 | 描述 |
265
+ | --------------- | -------------------------- | -------------- |
266
+ | completeColor | `(text: string) => string` | 已完成部分颜色 |
267
+ | incompleteColor | `(text: string) => string` | 未完成部分颜色 |
268
+ | percentageColor | `(text: string) => string` | 百分比数字颜色 |
269
+ | phaseColor | `(text: string) => string` | 阶段标签颜色 |
270
+ | moduleColor | `(text: string) => string` | 模块名称颜色 |
271
+
272
+ ```typescript
273
+ // 默认进度条格式
274
+ buildProgress()
275
+
276
+ // 旋转动画格式
277
+ buildProgress({ format: 'spinner' })
278
+
279
+ // 精简格式
280
+ buildProgress({ format: 'minimal' })
281
+
282
+ // 自定义外观
283
+ buildProgress({
284
+ width: 40,
285
+ completeChar: '■',
286
+ incompleteChar: '□',
287
+ clearOnComplete: false
288
+ })
289
+ ```
290
+
240
291
  ### copyFile
241
292
 
242
293
  在 Vite 构建完成后复制文件或目录到指定位置。
@@ -253,35 +304,35 @@ Logger.destroy()
253
304
 
254
305
  根据 uni-app 项目的 `pages.json` 自动生成路由配置文件。
255
306
 
256
- | 选项 | 类型 | 默认值 | 描述 |
257
- | -------------------- | ------------------------------------------------- | ---------------------- | ----------------------------- |
258
- | pagesJsonPath | string | 'src/pages.json' | pages.json 文件路径 |
259
- | outputPath | string | 'src/router.config.ts' | 输出文件路径 |
260
- | outputFormat | 'ts' \| 'js' | 'ts' | 输出文件格式 |
261
- | nameStrategy | 'path' \| 'camelCase' \| 'pascalCase' \| 'custom' | 'camelCase' | 路由名称策略 |
262
- | customNameGenerator | (path: string) => string | - | 自定义路由名称生成函数 |
263
- | includeSubPackages | boolean | true | 是否包含子包路由 |
264
- | watch | boolean | true | 是否监听变化自动重新生成 |
265
- | metaMapping | Record\<string, string\> | - | 页面 style 字段到 meta 的映射 |
266
- | exportTypes | boolean | true | 是否导出类型定义 |
267
- | preserveRouteChanges | boolean | true | 是否保留用户对 routes 的修改 |
307
+ | 选项 | 类型 | 默认值 | 描述 |
308
+ | -------------------- | --------------------------------------------------------- | ---------------------- | ----------------------------- |
309
+ | pagesJsonPath | string | 'src/pages.json' | pages.json 文件路径 |
310
+ | outputPath | string | 'src/router.config.ts' | 输出文件路径 |
311
+ | outputFormat | `'ts'` \| `'js'` | 'ts' | 输出文件格式 |
312
+ | nameStrategy | `'path'` \| `'camelCase'` \| `'pascalCase'` \| `'custom'` | 'camelCase' | 路由名称策略 |
313
+ | customNameGenerator | `(path: string) => string` | - | 自定义路由名称生成函数 |
314
+ | includeSubPackages | boolean | true | 是否包含子包路由 |
315
+ | watch | boolean | true | 是否监听变化自动重新生成 |
316
+ | metaMapping | `Record<string, string>` | - | 页面 style 字段到 meta 的映射 |
317
+ | exportTypes | boolean | true | 是否导出类型定义 |
318
+ | preserveRouteChanges | boolean | true | 是否保留用户对 routes 的修改 |
268
319
 
269
320
  ### generateVersion
270
321
 
271
322
  在 Vite 构建过程中自动生成版本号。
272
323
 
273
- | 选项 | 类型 | 默认值 | 描述 |
274
- | ------------ | --------------------------------------------------------------------- | ----------------- | ------------------------ |
275
- | format | 'timestamp' \| 'date' \| 'datetime' \| 'semver' \| 'hash' \| 'custom' | 'timestamp' | 版本号格式 |
276
- | customFormat | string | - | 自定义格式模板 |
277
- | semverBase | string | '1.0.0' | 语义化版本基础值 |
278
- | outputType | 'file' \| 'define' \| 'both' | 'file' | 输出类型 |
279
- | outputFile | string | 'version.json' | 输出文件路径 |
280
- | defineName | string | '**APP_VERSION**' | 注入的全局变量名 |
281
- | hashLength | number | 8 | 哈希长度(1-32) |
282
- | prefix | string | - | 版本号前缀 |
283
- | suffix | string | - | 版本号后缀 |
284
- | extra | Record\<string, unknown\> | - | 附加信息(仅 JSON 文件) |
324
+ | 选项 | 类型 | 默认值 | 描述 |
325
+ | ------------ | --------------------------------------------------------------------------------- | ----------------- | ------------------------ |
326
+ | format | `'timestamp'` \| `'date'` \| `'datetime'` \| `'semver'` \| `'hash'` \| `'custom'` | 'timestamp' | 版本号格式 |
327
+ | customFormat | string | - | 自定义格式模板 |
328
+ | semverBase | string | '1.0.0' | 语义化版本基础值 |
329
+ | outputType | `'file'` \| `'define'` \| `'both'` | 'file' | 输出类型 |
330
+ | outputFile | string | 'version.json' | 输出文件路径 |
331
+ | defineName | string | '**APP_VERSION**' | 注入的全局变量名 |
332
+ | hashLength | number | 8 | 哈希长度(1-32) |
333
+ | prefix | string | - | 版本号前缀 |
334
+ | suffix | string | - | 版本号后缀 |
335
+ | extra | `Record<string, unknown>` | - | 附加信息(仅 JSON 文件) |
285
336
 
286
337
  ### injectIco
287
338
 
@@ -304,23 +355,32 @@ Logger.destroy()
304
355
  | sizes | string | 否 | 图标尺寸 |
305
356
  | type | string | 否 | 图标 MIME 类型 |
306
357
 
358
+ `copyOptions` 接口定义:
359
+
360
+ | 属性 | 类型 | 必填 | 默认值 | 描述 |
361
+ | --------- | ------- | ---- | ------ | ---------------- |
362
+ | sourceDir | string | 是 | - | 图标源文件目录 |
363
+ | targetDir | string | 是 | - | 图标目标目录 |
364
+ | overwrite | boolean | 否 | true | 是否覆盖同名文件 |
365
+ | recursive | boolean | 否 | true | 是否递归复制 |
366
+
307
367
  ## 子路径导出
308
368
 
309
369
  支持按需导入模块,减少打包体积:
310
370
 
311
371
  ```typescript
312
372
  // 完整导入
313
- import { copyFile, BasePlugin, Logger } from '@meng-xi/vite-plugin'
373
+ import { buildProgress, copyFile, BasePlugin, Logger } from '@meng-xi/vite-plugin'
314
374
 
315
375
  // 按模块导入
316
376
  import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin/factory'
317
377
  import { Logger } from '@meng-xi/vite-plugin/logger'
318
- import { copyFile, generateRouter } from '@meng-xi/vite-plugin/plugins'
378
+ import { buildProgress, copyFile, generateRouter } from '@meng-xi/vite-plugin/plugins'
319
379
  import { Validator, readFileContent, writeFileContent } from '@meng-xi/vite-plugin/common'
320
380
 
321
381
  // 类型导入(从子路径按需导入类型定义)
322
382
  import type { PluginWithInstance, PluginFactory, BasePluginOptions } from '@meng-xi/vite-plugin/factory'
323
- import type { GenerateVersionOptions, InjectIcoOptions, Icon } from '@meng-xi/vite-plugin/plugins'
383
+ import type { BuildProgressOptions, GenerateVersionOptions, InjectIcoOptions, Icon } from '@meng-xi/vite-plugin/plugins'
324
384
  import type { DateFormatOptions } from '@meng-xi/vite-plugin/common'
325
385
  ```
326
386
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const format=require("./shared/vite-plugin.Ba9646wL.cjs"),validation=require("./shared/vite-plugin.IGZeStMa.cjs"),index=require("./shared/vite-plugin.CawoITTT.cjs"),logger_index=require("./logger/index.cjs"),index$1=require("./shared/vite-plugin.CXlzkIgT.cjs");require("fs"),require("path"),require("crypto"),exports.checkSourceExists=format.checkSourceExists,exports.copySourceToTarget=format.copySourceToTarget,exports.ensureTargetDir=format.ensureTargetDir,exports.fileExists=format.fileExists,exports.formatDate=format.formatDate,exports.generateRandomHash=format.generateRandomHash,exports.getDateFormatParams=format.getDateFormatParams,exports.padNumber=format.padNumber,exports.parseTemplate=format.parseTemplate,exports.readDirRecursive=format.readDirRecursive,exports.readFileContent=format.readFileContent,exports.readFileSync=format.readFileSync,exports.runWithConcurrency=format.runWithConcurrency,exports.shouldUpdateFile=format.shouldUpdateFile,exports.stripJsonComments=format.stripJsonComments,exports.toCamelCase=format.toCamelCase,exports.toPascalCase=format.toPascalCase,exports.writeFileContent=format.writeFileContent,exports.Validator=validation.Validator,exports.deepMerge=validation.deepMerge,exports.BasePlugin=index.BasePlugin,exports.createPluginFactory=index.createPluginFactory,exports.Logger=logger_index.Logger,exports.copyFile=index$1.copyFile,exports.generateRouter=index$1.generateRouter,exports.generateVersion=index$1.generateVersion,exports.injectIco=index$1.injectIco;
1
+ "use strict";const format=require("./shared/vite-plugin.Ba9646wL.cjs"),validation=require("./shared/vite-plugin.IGZeStMa.cjs"),index=require("./shared/vite-plugin.CawoITTT.cjs"),logger_index=require("./logger/index.cjs"),index$1=require("./shared/vite-plugin.DqgHJjxa.cjs");require("fs"),require("path"),require("crypto"),exports.checkSourceExists=format.checkSourceExists,exports.copySourceToTarget=format.copySourceToTarget,exports.ensureTargetDir=format.ensureTargetDir,exports.fileExists=format.fileExists,exports.formatDate=format.formatDate,exports.generateRandomHash=format.generateRandomHash,exports.getDateFormatParams=format.getDateFormatParams,exports.padNumber=format.padNumber,exports.parseTemplate=format.parseTemplate,exports.readDirRecursive=format.readDirRecursive,exports.readFileContent=format.readFileContent,exports.readFileSync=format.readFileSync,exports.runWithConcurrency=format.runWithConcurrency,exports.shouldUpdateFile=format.shouldUpdateFile,exports.stripJsonComments=format.stripJsonComments,exports.toCamelCase=format.toCamelCase,exports.toPascalCase=format.toPascalCase,exports.writeFileContent=format.writeFileContent,exports.Validator=validation.Validator,exports.deepMerge=validation.deepMerge,exports.BasePlugin=index.BasePlugin,exports.createPluginFactory=index.createPluginFactory,exports.Logger=logger_index.Logger,exports.buildProgress=index$1.buildProgress,exports.copyFile=index$1.copyFile,exports.generateRouter=index$1.generateRouter,exports.generateVersion=index$1.generateVersion,exports.injectIco=index$1.injectIco;
package/dist/index.d.cts CHANGED
@@ -2,5 +2,5 @@ export { DateFormatOptions, checkSourceExists, copySourceToTarget, deepMerge, en
2
2
  export { V as Validator } from './shared/vite-plugin.CiHfwMiN.cjs';
3
3
  export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.cjs';
4
4
  export { L as Logger, P as PluginLogger } from './shared/vite-plugin.CLr0ttuO.cjs';
5
- export { CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat, copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.cjs';
5
+ export { BuildPhase, BuildProgressOptions, CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, ProgressFormat, ProgressTheme, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat, buildProgress, copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.cjs';
6
6
  import 'vite';
package/dist/index.d.mts CHANGED
@@ -2,5 +2,5 @@ export { DateFormatOptions, checkSourceExists, copySourceToTarget, deepMerge, en
2
2
  export { V as Validator } from './shared/vite-plugin.CiHfwMiN.mjs';
3
3
  export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.mjs';
4
4
  export { L as Logger, P as PluginLogger } from './shared/vite-plugin.CLr0ttuO.mjs';
5
- export { CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat, copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.mjs';
5
+ export { BuildPhase, BuildProgressOptions, CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, ProgressFormat, ProgressTheme, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat, buildProgress, copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.mjs';
6
6
  import 'vite';
package/dist/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export { DateFormatOptions, checkSourceExists, copySourceToTarget, deepMerge, en
2
2
  export { V as Validator } from './shared/vite-plugin.CiHfwMiN.js';
3
3
  export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.js';
4
4
  export { L as Logger, P as PluginLogger } from './shared/vite-plugin.CLr0ttuO.js';
5
- export { CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat, copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.js';
5
+ export { BuildPhase, BuildProgressOptions, CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, ProgressFormat, ProgressTheme, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat, buildProgress, copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.js';
6
6
  import 'vite';
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{c as checkSourceExists,a as copySourceToTarget,e as ensureTargetDir,f as fileExists,b as formatDate,g as generateRandomHash,d as getDateFormatParams,p as padNumber,h as parseTemplate,r as readDirRecursive,i as readFileContent,j as readFileSync,k as runWithConcurrency,s as shouldUpdateFile,l as stripJsonComments,t as toCamelCase,m as toPascalCase,w as writeFileContent}from"./shared/vite-plugin.C3ejdBNf.mjs";export{V as Validator,d as deepMerge}from"./shared/vite-plugin.B88RyRN8.mjs";export{B as BasePlugin,c as createPluginFactory}from"./shared/vite-plugin.DSb6XzBn.mjs";export{Logger}from"./logger/index.mjs";export{c as copyFile,g as generateRouter,a as generateVersion,i as injectIco}from"./shared/vite-plugin.B5wW4CiL.mjs";import"fs";import"path";import"crypto";
1
+ export{c as checkSourceExists,a as copySourceToTarget,e as ensureTargetDir,f as fileExists,b as formatDate,g as generateRandomHash,d as getDateFormatParams,p as padNumber,h as parseTemplate,r as readDirRecursive,i as readFileContent,j as readFileSync,k as runWithConcurrency,s as shouldUpdateFile,l as stripJsonComments,t as toCamelCase,m as toPascalCase,w as writeFileContent}from"./shared/vite-plugin.C3ejdBNf.mjs";export{V as Validator,d as deepMerge}from"./shared/vite-plugin.B88RyRN8.mjs";export{B as BasePlugin,c as createPluginFactory}from"./shared/vite-plugin.DSb6XzBn.mjs";export{Logger}from"./logger/index.mjs";export{b as buildProgress,c as copyFile,g as generateRouter,a as generateVersion,i as injectIco}from"./shared/vite-plugin.CIahO6bu.mjs";import"fs";import"path";import"crypto";
@@ -1 +1 @@
1
- "use strict";const index=require("../shared/vite-plugin.CXlzkIgT.cjs");require("../shared/vite-plugin.CawoITTT.cjs"),require("../logger/index.cjs"),require("fs"),require("path"),require("crypto"),require("../shared/vite-plugin.IGZeStMa.cjs"),require("../shared/vite-plugin.Ba9646wL.cjs"),exports.copyFile=index.copyFile,exports.generateRouter=index.generateRouter,exports.generateVersion=index.generateVersion,exports.injectIco=index.injectIco;
1
+ "use strict";const index=require("../shared/vite-plugin.DqgHJjxa.cjs");require("../shared/vite-plugin.CawoITTT.cjs"),require("../logger/index.cjs"),require("fs"),require("path"),require("crypto"),require("../shared/vite-plugin.IGZeStMa.cjs"),require("../shared/vite-plugin.Ba9646wL.cjs"),exports.buildProgress=index.buildProgress,exports.copyFile=index.copyFile,exports.generateRouter=index.generateRouter,exports.generateVersion=index.generateVersion,exports.injectIco=index.injectIco;
@@ -3,6 +3,186 @@ import 'vite';
3
3
  import '../shared/vite-plugin.CLr0ttuO.cjs';
4
4
  import '../shared/vite-plugin.CiHfwMiN.cjs';
5
5
 
6
+ /**
7
+ * 进度条显示格式类型
8
+ *
9
+ * @description
10
+ * - 'bar': 完整进度条模式,显示旋转动画 + 阶段标签 + 进度条 + 百分比 + 模块名
11
+ * - 'spinner': 旋转动画模式,显示旋转动画 + 阶段标签 + 百分比
12
+ * - 'minimal': 精简模式,仅显示阶段标签 + 百分比
13
+ */
14
+ type ProgressFormat = 'bar' | 'spinner' | 'minimal';
15
+ /**
16
+ * 构建进度插件的配置选项接口
17
+ *
18
+ * @interface BuildProgressOptions
19
+ */
20
+ interface BuildProgressOptions extends BasePluginOptions {
21
+ /**
22
+ * 进度条宽度(字符数)
23
+ *
24
+ * @default 30
25
+ */
26
+ width?: number;
27
+ /**
28
+ * 进度条显示格式
29
+ *
30
+ * @default 'bar'
31
+ */
32
+ format?: ProgressFormat;
33
+ /**
34
+ * 已完成部分的填充字符
35
+ *
36
+ * @default '█'
37
+ * @example '█'、'■'、'='
38
+ */
39
+ completeChar?: string;
40
+ /**
41
+ * 未完成部分的填充字符
42
+ *
43
+ * @default '░'
44
+ * @example '░'、'□'、'-'
45
+ */
46
+ incompleteChar?: string;
47
+ /**
48
+ * 构建完成后是否清除进度条
49
+ *
50
+ * @default true
51
+ * @description 设为 false 时,构建完成后保留 100% 进度条在终端中
52
+ */
53
+ clearOnComplete?: boolean;
54
+ /**
55
+ * 是否显示当前正在处理的模块名称
56
+ *
57
+ * @default true
58
+ * @description 仅在 transform 阶段显示,模块名超长时自动截断
59
+ */
60
+ showModuleName?: boolean;
61
+ /**
62
+ * 自定义颜色主题
63
+ *
64
+ * @remarks
65
+ * 每个属性是一个接受字符串并返回带 ANSI 颜色码字符串的函数。
66
+ * 未提供的属性将使用默认主题。
67
+ */
68
+ theme?: ProgressTheme;
69
+ }
70
+ /**
71
+ * 进度条颜色主题接口
72
+ *
73
+ * @interface ProgressTheme
74
+ * @description 定义进度条各部分的颜色渲染函数,每个函数接受文本并返回带 ANSI 颜色码的字符串
75
+ */
76
+ interface ProgressTheme {
77
+ /**
78
+ * 已完成部分的颜色渲染函数
79
+ *
80
+ * @param text - 需要着色的文本
81
+ * @returns 带 ANSI 颜色码的字符串
82
+ */
83
+ completeColor: (text: string) => string;
84
+ /**
85
+ * 未完成部分的颜色渲染函数
86
+ *
87
+ * @param text - 需要着色的文本
88
+ * @returns 带 ANSI 颜色码的字符串
89
+ */
90
+ incompleteColor: (text: string) => string;
91
+ /**
92
+ * 百分比数字的颜色渲染函数
93
+ *
94
+ * @param text - 需要着色的文本
95
+ * @returns 带 ANSI 颜色码的字符串
96
+ */
97
+ percentageColor: (text: string) => string;
98
+ /**
99
+ * 阶段标签的颜色渲染函数
100
+ *
101
+ * @param text - 需要着色的文本
102
+ * @returns 带 ANSI 颜色码的字符串
103
+ */
104
+ phaseColor: (text: string) => string;
105
+ /**
106
+ * 模块名称的颜色渲染函数
107
+ *
108
+ * @param text - 需要着色的文本
109
+ * @returns 带 ANSI 颜色码的字符串
110
+ */
111
+ moduleColor: (text: string) => string;
112
+ }
113
+ /**
114
+ * 构建阶段类型
115
+ *
116
+ * @description
117
+ * - 'idle': 空闲状态,插件尚未开始工作
118
+ * - 'config': 读取配置阶段
119
+ * - 'resolve': 解析模块依赖阶段
120
+ * - 'transform': 转换模块阶段
121
+ * - 'bundle': 打包阶段(仅生产构建)
122
+ * - 'write': 写入文件阶段
123
+ * - 'done': 构建完成
124
+ */
125
+ type BuildPhase = 'idle' | 'config' | 'resolve' | 'transform' | 'bundle' | 'write' | 'done';
126
+
127
+ /**
128
+ * 构建进度条插件
129
+ *
130
+ * @param {BuildProgressOptions} options - 插件配置选项
131
+ * @returns {Plugin} 一个 Vite 插件实例
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // 基本使用 - 默认进度条格式
136
+ * buildProgress()
137
+ *
138
+ * // 旋转动画格式
139
+ * buildProgress({
140
+ * format: 'spinner'
141
+ * })
142
+ *
143
+ * // 精简格式
144
+ * buildProgress({
145
+ * format: 'minimal'
146
+ * })
147
+ *
148
+ * // 自定义进度条外观
149
+ * buildProgress({
150
+ * width: 40,
151
+ * completeChar: '■',
152
+ * incompleteChar: '□',
153
+ * clearOnComplete: false
154
+ * })
155
+ *
156
+ * // 自定义颜色主题
157
+ * buildProgress({
158
+ * theme: {
159
+ * completeColor: (t) => `\x1b[32m${t}\x1b[39m`,
160
+ * incompleteColor: (t) => `\x1b[90m${t}\x1b[39m`,
161
+ * percentageColor: (t) => `\x1b[1m${t}\x1b[22m`,
162
+ * phaseColor: (t) => `\x1b[36m${t}\x1b[39m`,
163
+ * moduleColor: (t) => `\x1b[90m${t}\x1b[39m`
164
+ * }
165
+ * })
166
+ *
167
+ * // 禁用模块名显示
168
+ * buildProgress({
169
+ * showModuleName: false
170
+ * })
171
+ * ```
172
+ *
173
+ * @remarks
174
+ * 该插件在 Vite 构建过程中实时显示终端进度条,支持三种显示格式:
175
+ * - bar: 完整进度条(默认),包含旋转动画、阶段标签、进度条和百分比
176
+ * - spinner: 旋转动画模式,仅显示动画、阶段标签和百分比
177
+ * - minimal: 精简模式,仅显示阶段标签和百分比
178
+ *
179
+ * 进度计算基于 Vite 构建生命周期:
180
+ * 1. config 阶段(5%)→ resolve 阶段(10%)→ transform 阶段(15%-85%)→ bundle 阶段(+10%)→ write 阶段(+5%)→ 完成(100%)
181
+ *
182
+ * 在非 TTY 终端环境下(如 CI/CD),自动降级为日志输出模式。
183
+ */
184
+ declare const buildProgress: PluginFactory<BuildProgressOptions, BuildProgressOptions>;
185
+
6
186
  /**
7
187
  * 复制文件插件的配置选项接口
8
188
  *
@@ -576,5 +756,5 @@ interface InjectIcoOptions extends BasePluginOptions {
576
756
  */
577
757
  declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
578
758
 
579
- export { copyFile, generateRouter, generateVersion, injectIco };
580
- export type { CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat };
759
+ export { buildProgress, copyFile, generateRouter, generateVersion, injectIco };
760
+ export type { BuildPhase, BuildProgressOptions, CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, ProgressFormat, ProgressTheme, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat };
@@ -3,6 +3,186 @@ import 'vite';
3
3
  import '../shared/vite-plugin.CLr0ttuO.mjs';
4
4
  import '../shared/vite-plugin.CiHfwMiN.mjs';
5
5
 
6
+ /**
7
+ * 进度条显示格式类型
8
+ *
9
+ * @description
10
+ * - 'bar': 完整进度条模式,显示旋转动画 + 阶段标签 + 进度条 + 百分比 + 模块名
11
+ * - 'spinner': 旋转动画模式,显示旋转动画 + 阶段标签 + 百分比
12
+ * - 'minimal': 精简模式,仅显示阶段标签 + 百分比
13
+ */
14
+ type ProgressFormat = 'bar' | 'spinner' | 'minimal';
15
+ /**
16
+ * 构建进度插件的配置选项接口
17
+ *
18
+ * @interface BuildProgressOptions
19
+ */
20
+ interface BuildProgressOptions extends BasePluginOptions {
21
+ /**
22
+ * 进度条宽度(字符数)
23
+ *
24
+ * @default 30
25
+ */
26
+ width?: number;
27
+ /**
28
+ * 进度条显示格式
29
+ *
30
+ * @default 'bar'
31
+ */
32
+ format?: ProgressFormat;
33
+ /**
34
+ * 已完成部分的填充字符
35
+ *
36
+ * @default '█'
37
+ * @example '█'、'■'、'='
38
+ */
39
+ completeChar?: string;
40
+ /**
41
+ * 未完成部分的填充字符
42
+ *
43
+ * @default '░'
44
+ * @example '░'、'□'、'-'
45
+ */
46
+ incompleteChar?: string;
47
+ /**
48
+ * 构建完成后是否清除进度条
49
+ *
50
+ * @default true
51
+ * @description 设为 false 时,构建完成后保留 100% 进度条在终端中
52
+ */
53
+ clearOnComplete?: boolean;
54
+ /**
55
+ * 是否显示当前正在处理的模块名称
56
+ *
57
+ * @default true
58
+ * @description 仅在 transform 阶段显示,模块名超长时自动截断
59
+ */
60
+ showModuleName?: boolean;
61
+ /**
62
+ * 自定义颜色主题
63
+ *
64
+ * @remarks
65
+ * 每个属性是一个接受字符串并返回带 ANSI 颜色码字符串的函数。
66
+ * 未提供的属性将使用默认主题。
67
+ */
68
+ theme?: ProgressTheme;
69
+ }
70
+ /**
71
+ * 进度条颜色主题接口
72
+ *
73
+ * @interface ProgressTheme
74
+ * @description 定义进度条各部分的颜色渲染函数,每个函数接受文本并返回带 ANSI 颜色码的字符串
75
+ */
76
+ interface ProgressTheme {
77
+ /**
78
+ * 已完成部分的颜色渲染函数
79
+ *
80
+ * @param text - 需要着色的文本
81
+ * @returns 带 ANSI 颜色码的字符串
82
+ */
83
+ completeColor: (text: string) => string;
84
+ /**
85
+ * 未完成部分的颜色渲染函数
86
+ *
87
+ * @param text - 需要着色的文本
88
+ * @returns 带 ANSI 颜色码的字符串
89
+ */
90
+ incompleteColor: (text: string) => string;
91
+ /**
92
+ * 百分比数字的颜色渲染函数
93
+ *
94
+ * @param text - 需要着色的文本
95
+ * @returns 带 ANSI 颜色码的字符串
96
+ */
97
+ percentageColor: (text: string) => string;
98
+ /**
99
+ * 阶段标签的颜色渲染函数
100
+ *
101
+ * @param text - 需要着色的文本
102
+ * @returns 带 ANSI 颜色码的字符串
103
+ */
104
+ phaseColor: (text: string) => string;
105
+ /**
106
+ * 模块名称的颜色渲染函数
107
+ *
108
+ * @param text - 需要着色的文本
109
+ * @returns 带 ANSI 颜色码的字符串
110
+ */
111
+ moduleColor: (text: string) => string;
112
+ }
113
+ /**
114
+ * 构建阶段类型
115
+ *
116
+ * @description
117
+ * - 'idle': 空闲状态,插件尚未开始工作
118
+ * - 'config': 读取配置阶段
119
+ * - 'resolve': 解析模块依赖阶段
120
+ * - 'transform': 转换模块阶段
121
+ * - 'bundle': 打包阶段(仅生产构建)
122
+ * - 'write': 写入文件阶段
123
+ * - 'done': 构建完成
124
+ */
125
+ type BuildPhase = 'idle' | 'config' | 'resolve' | 'transform' | 'bundle' | 'write' | 'done';
126
+
127
+ /**
128
+ * 构建进度条插件
129
+ *
130
+ * @param {BuildProgressOptions} options - 插件配置选项
131
+ * @returns {Plugin} 一个 Vite 插件实例
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // 基本使用 - 默认进度条格式
136
+ * buildProgress()
137
+ *
138
+ * // 旋转动画格式
139
+ * buildProgress({
140
+ * format: 'spinner'
141
+ * })
142
+ *
143
+ * // 精简格式
144
+ * buildProgress({
145
+ * format: 'minimal'
146
+ * })
147
+ *
148
+ * // 自定义进度条外观
149
+ * buildProgress({
150
+ * width: 40,
151
+ * completeChar: '■',
152
+ * incompleteChar: '□',
153
+ * clearOnComplete: false
154
+ * })
155
+ *
156
+ * // 自定义颜色主题
157
+ * buildProgress({
158
+ * theme: {
159
+ * completeColor: (t) => `\x1b[32m${t}\x1b[39m`,
160
+ * incompleteColor: (t) => `\x1b[90m${t}\x1b[39m`,
161
+ * percentageColor: (t) => `\x1b[1m${t}\x1b[22m`,
162
+ * phaseColor: (t) => `\x1b[36m${t}\x1b[39m`,
163
+ * moduleColor: (t) => `\x1b[90m${t}\x1b[39m`
164
+ * }
165
+ * })
166
+ *
167
+ * // 禁用模块名显示
168
+ * buildProgress({
169
+ * showModuleName: false
170
+ * })
171
+ * ```
172
+ *
173
+ * @remarks
174
+ * 该插件在 Vite 构建过程中实时显示终端进度条,支持三种显示格式:
175
+ * - bar: 完整进度条(默认),包含旋转动画、阶段标签、进度条和百分比
176
+ * - spinner: 旋转动画模式,仅显示动画、阶段标签和百分比
177
+ * - minimal: 精简模式,仅显示阶段标签和百分比
178
+ *
179
+ * 进度计算基于 Vite 构建生命周期:
180
+ * 1. config 阶段(5%)→ resolve 阶段(10%)→ transform 阶段(15%-85%)→ bundle 阶段(+10%)→ write 阶段(+5%)→ 完成(100%)
181
+ *
182
+ * 在非 TTY 终端环境下(如 CI/CD),自动降级为日志输出模式。
183
+ */
184
+ declare const buildProgress: PluginFactory<BuildProgressOptions, BuildProgressOptions>;
185
+
6
186
  /**
7
187
  * 复制文件插件的配置选项接口
8
188
  *
@@ -576,5 +756,5 @@ interface InjectIcoOptions extends BasePluginOptions {
576
756
  */
577
757
  declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
578
758
 
579
- export { copyFile, generateRouter, generateVersion, injectIco };
580
- export type { CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat };
759
+ export { buildProgress, copyFile, generateRouter, generateVersion, injectIco };
760
+ export type { BuildPhase, BuildProgressOptions, CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, ProgressFormat, ProgressTheme, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat };