@meng-xi/vite-plugin 0.0.5 → 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.
Files changed (46) hide show
  1. package/README-en.md +404 -182
  2. package/README.md +403 -182
  3. package/dist/common/index.cjs +1 -1
  4. package/dist/common/index.d.cts +9 -1
  5. package/dist/common/index.d.mts +9 -1
  6. package/dist/common/index.d.ts +9 -1
  7. package/dist/common/index.mjs +1 -1
  8. package/dist/factory/index.cjs +1 -1
  9. package/dist/factory/index.d.cts +71 -6
  10. package/dist/factory/index.d.mts +71 -6
  11. package/dist/factory/index.d.ts +71 -6
  12. package/dist/factory/index.mjs +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +4 -5
  15. package/dist/index.d.mts +4 -5
  16. package/dist/index.d.ts +4 -5
  17. package/dist/index.mjs +1 -1
  18. package/dist/logger/index.cjs +1 -1
  19. package/dist/logger/index.d.cts +1 -1
  20. package/dist/logger/index.d.mts +1 -1
  21. package/dist/logger/index.d.ts +1 -1
  22. package/dist/logger/index.mjs +1 -1
  23. package/dist/plugins/index.cjs +1 -1
  24. package/dist/plugins/index.d.cts +263 -8
  25. package/dist/plugins/index.d.mts +263 -8
  26. package/dist/plugins/index.d.ts +263 -8
  27. package/dist/plugins/index.mjs +1 -1
  28. package/dist/shared/vite-plugin.Ba9646wL.cjs +1 -0
  29. package/dist/shared/vite-plugin.C3ejdBNf.mjs +1 -0
  30. package/dist/shared/vite-plugin.CIahO6bu.mjs +37 -0
  31. package/dist/shared/{vite-plugin.B3PARlU9.d.cts → vite-plugin.CLr0ttuO.d.cts} +16 -0
  32. package/dist/shared/{vite-plugin.B3PARlU9.d.mts → vite-plugin.CLr0ttuO.d.mts} +16 -0
  33. package/dist/shared/{vite-plugin.B3PARlU9.d.ts → vite-plugin.CLr0ttuO.d.ts} +16 -0
  34. package/dist/shared/vite-plugin.CawoITTT.cjs +1 -0
  35. package/dist/shared/vite-plugin.DSb6XzBn.mjs +1 -0
  36. package/dist/shared/vite-plugin.DqgHJjxa.cjs +37 -0
  37. package/package.json +72 -72
  38. package/dist/shared/vite-plugin.BZsetDCm.cjs +0 -1
  39. package/dist/shared/vite-plugin.C7isVPKg.mjs +0 -1
  40. package/dist/shared/vite-plugin.CS9a5kjK.mjs +0 -36
  41. package/dist/shared/vite-plugin.CgnG5_UX.cjs +0 -36
  42. package/dist/shared/vite-plugin.DqWt65U-.cjs +0 -1
  43. package/dist/shared/vite-plugin.UkE7CdSe.d.cts +0 -43
  44. package/dist/shared/vite-plugin.UkE7CdSe.d.mts +0 -43
  45. package/dist/shared/vite-plugin.UkE7CdSe.d.ts +0 -43
  46. package/dist/shared/vite-plugin.YvjM8LxW.mjs +0 -1
package/README.md CHANGED
@@ -1,182 +1,403 @@
1
- **中文** | [English](./README-en.md)
2
-
3
- <div align="center">
4
- <a href="https://github.com/MengXi-Studio/vite-plugin">
5
- <img alt="梦曦工作室 Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.svg">
6
- </a>
7
- <br>
8
- <h1>@meng-xi/vite-plugin</h1>
9
- <p>一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架</p>
10
-
11
- [![license](https://img.shields.io/github/license/MengXi-Studio/vite-plugin.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@meng-xi/vite-plugin?color=blue)](https://www.npmjs.com/package/@meng-xi/vite-plugin)
12
- ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
13
-
14
- </div>
15
-
16
- ## 特性
17
-
18
- - **开箱即用** - 提供文件复制、路由生成、版本管理、图标注入等实用插件
19
- - **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义插件
20
- - **类型安全** - 完整的 TypeScript 类型定义,配置验证器确保参数正确性
21
- - **灵活配置** - 所有插件支持详细配置,满足多样化场景需求
22
-
23
- ## 文档
24
-
25
- 查看完整文档:[https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
26
-
27
- ## 安装
28
-
29
- ```bash
30
- # npm
31
- npm install @meng-xi/vite-plugin -D
32
-
33
- # yarn
34
- yarn add @meng-xi/vite-plugin -D
35
-
36
- # pnpm
37
- pnpm add @meng-xi/vite-plugin -D
38
- ```
39
-
40
- ## 快速开始
41
-
42
- ### 使用内置插件
43
-
44
- ```typescript
45
- import { defineConfig } from 'vite'
46
- import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
47
-
48
- export default defineConfig({
49
- plugins: [
50
- // 复制文件
51
- copyFile({
52
- sourceDir: 'src/assets',
53
- targetDir: 'dist/assets'
54
- }),
55
-
56
- // 生成路由配置(uni-app)
57
- generateRouter({
58
- pagesJsonPath: 'src/pages.json',
59
- outputPath: 'src/router.config.ts'
60
- }),
61
-
62
- // 生成版本号
63
- generateVersion({
64
- format: 'datetime',
65
- outputType: 'both'
66
- }),
67
-
68
- // 注入网站图标
69
- injectIco({
70
- base: '/assets'
71
- })
72
- ]
73
- })
74
- ```
75
-
76
- ### 开发自定义插件
77
-
78
- ```typescript
79
- import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
80
- import type { Plugin } from 'vite'
81
-
82
- interface MyPluginOptions {
83
- path: string
84
- enabled?: boolean
85
- verbose?: boolean
86
- errorStrategy?: 'throw' | 'log' | 'ignore'
87
- }
88
-
89
- class MyPlugin extends BasePlugin<MyPluginOptions> {
90
- protected getDefaultOptions() {
91
- return { path: './default' }
92
- }
93
-
94
- protected validateOptions(): void {
95
- this.validator.field('path').required().string().validate()
96
- }
97
-
98
- protected getPluginName(): string {
99
- return 'my-plugin'
100
- }
101
-
102
- protected addPluginHooks(plugin: Plugin): void {
103
- plugin.buildStart = () => {
104
- this.logger.info(`Plugin started with path: ${this.options.path}`)
105
- }
106
- }
107
- }
108
-
109
- export const myPlugin = createPluginFactory(MyPlugin)
110
- ```
111
-
112
- ## 内置插件
113
-
114
- ### copyFile
115
-
116
- Vite 构建完成后复制文件或目录到指定位置。
117
-
118
- | 选项 | 类型 | 默认值 | 描述 |
119
- | ----------- | ------- | ------ | -------------------- |
120
- | sourceDir | string | - | 源目录路径(必填) |
121
- | targetDir | string | - | 目标目录路径(必填) |
122
- | overwrite | boolean | true | 是否覆盖现有文件 |
123
- | recursive | boolean | true | 是否递归复制子目录 |
124
- | incremental | boolean | true | 是否启用增量复制 |
125
-
126
- ### generateRouter
127
-
128
- 根据 uni-app 项目的 `pages.json` 自动生成路由配置文件。
129
-
130
- | 选项 | 类型 | 默认值 | 描述 |
131
- | -------------------- | ------------ | ---------------------- | ----------------------------- |
132
- | pagesJsonPath | string | 'src/pages.json' | pages.json 文件路径 |
133
- | outputPath | string | 'src/router.config.ts' | 输出文件路径 |
134
- | outputFormat | 'ts' \| 'js' | 'ts' | 输出文件格式 |
135
- | nameStrategy | string | 'camelCase' | 路由名称策略 |
136
- | includeSubPackages | boolean | true | 是否包含子包路由 |
137
- | watch | boolean | true | 是否监听变化自动重新生成 |
138
- | metaMapping | object | - | 页面 style 字段到 meta 的映射 |
139
- | preserveRouteChanges | boolean | true | 是否保留用户对 routes 的修改 |
140
-
141
- ### generateVersion
142
-
143
- Vite 构建过程中自动生成版本号。
144
-
145
- | 选项 | 类型 | 默认值 | 描述 |
146
- | ---------- | ------ | --------------------- | ---------------- |
147
- | format | string | 'timestamp' | 版本格式 |
148
- | outputType | string | 'file' | 输出类型 |
149
- | outputFile | string | 'version.json' | 输出文件路径 |
150
- | defineName | string | '\_\_APP_VERSION\_\_' | 注入的全局变量名 |
151
- | prefix | string | - | 版本号前缀 |
152
- | suffix | string | - | 版本号后缀 |
153
-
154
- ### injectIco
155
-
156
- Vite 构建过程中将网站图标链接注入到 HTML 文件的 head 中。
157
-
158
- | 选项 | 类型 | 默认值 | 描述 |
159
- | ----------- | ------ | ------ | --------------------------- |
160
- | base | string | - | 图标文件的基础路径 |
161
- | url | string | - | 图标的完整 URL |
162
- | link | string | - | 自定义完整的 link 标签 HTML |
163
- | icons | array | - | 自定义图标数组 |
164
- | copyOptions | object | - | 图标文件复制配置 |
165
-
166
- ## 更新日志
167
-
168
- 查看 [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
169
-
170
- ## 贡献指南
171
-
172
- 欢迎贡献代码!请按以下步骤操作:
173
-
174
- 1. Fork 本项目
175
- 2. 创建功能分支:`git checkout -b feature/your-feature`
176
- 3. 提交变更:`git commit -m "feat: your feature description"`
177
- 4. 推送分支:`git push origin feature/your-feature`
178
- 5. 创建 Pull Request
179
-
180
- ## License
181
-
182
- [MIT](LICENSE)
1
+ **中文** | [English](./README-en.md)
2
+
3
+ <div align="center">
4
+ <a href="https://github.com/MengXi-Studio/vite-plugin">
5
+ <img alt="梦曦工作室 Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.png">
6
+ </a>
7
+ <br>
8
+ <h1>@meng-xi/vite-plugin</h1>
9
+ <p>一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架</p>
10
+
11
+ [![license](https://img.shields.io/github/license/MengXi-Studio/vite-plugin.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@meng-xi/vite-plugin?color=blue)](https://www.npmjs.com/package/@meng-xi/vite-plugin)
12
+ ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
13
+
14
+ </div>
15
+
16
+ ## 特性
17
+
18
+ - **开箱即用** - 提供 buildProgress、copyFile、generateRouter、generateVersion、injectIco 五个实用插件,覆盖构建进度展示、文件复制、路由生成、版本管理、图标注入等常见场景
19
+ - **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建符合规范的自定义 Vite 插件
20
+ - **完整生命周期** - 支持初始化、配置解析、销毁等生命周期管理,自动组合钩子逻辑
21
+ - **类型安全** - 完整的 TypeScript 类型定义,配置验证器确保参数正确性
22
+ - **灵活配置** - 所有插件支持详细配置,满足多样化场景需求
23
+ - **安全执行** - 内置错误处理策略(throw / log / ignore),统一异常管理
24
+
25
+ ## 文档
26
+
27
+ 查看完整文档:[https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
28
+
29
+ ## 安装
30
+
31
+ ::: code-group
32
+
33
+ ```bash [npm]
34
+ npm install @meng-xi/vite-plugin -D
35
+ ```
36
+
37
+ ```bash [yarn]
38
+ yarn add @meng-xi/vite-plugin -D
39
+ ```
40
+
41
+ ```bash [pnpm]
42
+ pnpm add @meng-xi/vite-plugin -D
43
+ ```
44
+
45
+ :::
46
+
47
+ ## 快速开始
48
+
49
+ ### 使用内置插件
50
+
51
+ ```typescript
52
+ import { defineConfig } from 'vite'
53
+ import { buildProgress, copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
54
+
55
+ export default defineConfig({
56
+ plugins: [
57
+ // 构建进度条
58
+ buildProgress(),
59
+
60
+ // 复制文件
61
+ copyFile({
62
+ sourceDir: 'src/assets',
63
+ targetDir: 'dist/assets'
64
+ }),
65
+
66
+ // 生成路由配置(uni-app)
67
+ generateRouter({
68
+ pagesJsonPath: 'src/pages.json',
69
+ outputPath: 'src/router.config.ts'
70
+ }),
71
+
72
+ // 生成版本号
73
+ generateVersion({
74
+ format: 'datetime',
75
+ outputType: 'both'
76
+ }),
77
+
78
+ // 注入网站图标
79
+ injectIco({
80
+ base: '/assets'
81
+ })
82
+ ]
83
+ })
84
+ ```
85
+
86
+ ### 访问插件实例
87
+
88
+ 所有内置插件返回的对象包含 `pluginInstance` 属性,可访问插件内部状态:
89
+
90
+ ```typescript
91
+ import type { PluginWithInstance } from '@meng-xi/vite-plugin/factory'
92
+ import type { GenerateRouterOptions } from '@meng-xi/vite-plugin'
93
+
94
+ const routerPlugin = generateRouter({ watch: true }) as PluginWithInstance<GenerateRouterOptions>
95
+
96
+ // 通过 pluginInstance 访问插件内部
97
+ console.log(routerPlugin.pluginInstance?.options)
98
+ ```
99
+
100
+ ### 开发自定义插件
101
+
102
+ ```typescript
103
+ import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
104
+ import type { BasePluginOptions, PluginWithInstance } from '@meng-xi/vite-plugin/factory'
105
+ import type { Plugin } from 'vite'
106
+
107
+ interface MyPluginOptions extends BasePluginOptions {
108
+ path: string
109
+ }
110
+
111
+ class MyPlugin extends BasePlugin<MyPluginOptions> {
112
+ protected getDefaultOptions() {
113
+ return { path: './default' }
114
+ }
115
+
116
+ protected validateOptions(): void {
117
+ this.validator.field('path').required().string().validate()
118
+ }
119
+
120
+ protected getPluginName(): string {
121
+ return 'my-plugin'
122
+ }
123
+
124
+ protected addPluginHooks(plugin: Plugin): void {
125
+ plugin.buildStart = () => {
126
+ this.logger.info(`Plugin started with path: ${this.options.path}`)
127
+ }
128
+ }
129
+
130
+ protected destroy(): void {
131
+ super.destroy()
132
+ // 自定义清理逻辑,如关闭连接、停止监听等
133
+ }
134
+ }
135
+
136
+ export const myPlugin = createPluginFactory(MyPlugin)
137
+ ```
138
+
139
+ ## 插件开发框架
140
+
141
+ ### BasePlugin 核心概念
142
+
143
+ `BasePlugin` 是所有插件的基类,提供了完整的生命周期管理和开发规范:
144
+
145
+ #### 生命周期
146
+
147
+ | 阶段 | 方法 | 说明 |
148
+ | -------- | ------------------ | -------------------------------------- |
149
+ | 初始化 | `constructor` | 合并配置、初始化日志和验证器 |
150
+ | 配置解析 | `onConfigResolved` | Vite 配置解析完成时调用 |
151
+ | 钩子注册 | `addPluginHooks` | 注册 Vite 插件钩子 |
152
+ | 销毁 | `destroy` | `closeBundle` 时自动调用,用于清理资源 |
153
+
154
+ #### 钩子自动组合
155
+
156
+ `toPlugin()` 方法会自动组合以下钩子:
157
+
158
+ - **configResolved** - 先执行基类的 `onConfigResolved`,再执行子类注册的钩子
159
+ - **closeBundle** - 先执行子类注册的钩子,再执行基类的 `destroy`
160
+
161
+ > 子类无需手动注册 `closeBundle` 钩子来清理资源,只需重写 `destroy()` 方法即可。
162
+
163
+ #### 必须实现的方法
164
+
165
+ | 方法 | 说明 |
166
+ | ------------------------ | ------------------ |
167
+ | `getPluginName()` | 返回插件名称 |
168
+ | `addPluginHooks(plugin)` | 添加 Vite 插件钩子 |
169
+
170
+ #### 可选重写的方法
171
+
172
+ | 方法 | 默认行为 | 说明 |
173
+ | -------------------------- | ----------- | ---------------------------------- |
174
+ | `getDefaultOptions()` | 返回 `{}` | 提供插件默认配置 |
175
+ | `validateOptions()` | 无验证 | 验证配置参数 |
176
+ | `getEnforce()` | `undefined` | 插件执行时机(`'pre'` / `'post'`) |
177
+ | `onConfigResolved(config)` | 存储配置 | 配置解析完成回调 |
178
+ | `destroy()` | 注销日志 | 插件销毁时的清理逻辑 |
179
+
180
+ #### 内置属性
181
+
182
+ | 属性 | 类型 | 说明 |
183
+ | ------------ | ------------------------ | ----------------- |
184
+ | `options` | `Required<T>` | 合并后的完整配置 |
185
+ | `logger` | `PluginLogger` | 插件日志记录器 |
186
+ | `validator` | `Validator<T>` | 配置验证器 |
187
+ | `viteConfig` | `ResolvedConfig \| null` | Vite 解析后的配置 |
188
+
189
+ #### 错误处理策略
190
+
191
+ 通过 `errorStrategy` 配置项控制错误行为:
192
+
193
+ - `'throw'`(默认)- 记录错误并抛出异常,中断构建
194
+ - `'log'` - 记录错误但不抛出,继续执行
195
+ - `'ignore'` - 记录错误但不抛出,继续执行
196
+
197
+ 使用 `safeExecute` / `safeExecuteSync` 包裹可能出错的操作:
198
+
199
+ ```typescript
200
+ const result = await this.safeExecute(async () => {
201
+ return await someAsyncOperation()
202
+ }, '执行异步操作')
203
+ ```
204
+
205
+ ### createPluginFactory
206
+
207
+ 创建插件工厂函数,支持选项标准化器:
208
+
209
+ ```typescript
210
+ // 基本使用
211
+ const myPlugin = createPluginFactory(MyPlugin)
212
+
213
+ // 带标准化器(支持字符串简写配置)
214
+ const myPlugin = createPluginFactory(MyPlugin, opt => (typeof opt === 'string' ? { path: opt } : opt))
215
+
216
+ // 使用时支持简写
217
+ myPlugin('./custom-path')
218
+ ```
219
+
220
+ ### Logger
221
+
222
+ 全局单例日志管理器,为每个插件提供独立的日志控制:
223
+
224
+ ```typescript
225
+ import { Logger } from '@meng-xi/vite-plugin/logger'
226
+
227
+ // 创建日志记录器(通常由 BasePlugin 自动调用)
228
+ Logger.create({ name: 'my-plugin', enabled: true })
229
+
230
+ // 注销插件日志配置(插件销毁时自动调用)
231
+ Logger.unregister('my-plugin')
232
+
233
+ // 销毁单例(测试场景使用)
234
+ Logger.destroy()
235
+ ```
236
+
237
+ 日志输出格式:
238
+
239
+ ```
240
+ ℹ️ [@meng-xi/vite-plugin:my-plugin] Info message
241
+ ✅ [@meng-xi/vite-plugin:my-plugin] Success message
242
+ ⚠️ [@meng-xi/vite-plugin:my-plugin] Warning message
243
+ ❌ [@meng-xi/vite-plugin:my-plugin] Error message
244
+ ```
245
+
246
+ ## 内置插件
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
+
291
+ ### copyFile
292
+
293
+ 在 Vite 构建完成后复制文件或目录到指定位置。
294
+
295
+ | 选项 | 类型 | 默认值 | 描述 |
296
+ | ----------- | ------- | ------ | -------------------- |
297
+ | sourceDir | string | - | 源目录路径(必填) |
298
+ | targetDir | string | - | 目标目录路径(必填) |
299
+ | overwrite | boolean | true | 是否覆盖现有文件 |
300
+ | recursive | boolean | true | 是否递归复制子目录 |
301
+ | incremental | boolean | true | 是否启用增量复制 |
302
+
303
+ ### generateRouter
304
+
305
+ 根据 uni-app 项目的 `pages.json` 自动生成路由配置文件。
306
+
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 的修改 |
319
+
320
+ ### generateVersion
321
+
322
+ 在 Vite 构建过程中自动生成版本号。
323
+
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 文件) |
336
+
337
+ ### injectIco
338
+
339
+ 在 Vite 构建过程中将网站图标链接注入到 HTML 文件的 head 中。
340
+
341
+ | 选项 | 类型 | 默认值 | 描述 |
342
+ | ----------- | ------ | ------ | --------------------------- |
343
+ | base | string | '/' | 图标文件的基础路径 |
344
+ | url | string | - | 图标的完整 URL |
345
+ | link | string | - | 自定义完整的 link 标签 HTML |
346
+ | icons | Icon[] | - | 自定义图标数组 |
347
+ | copyOptions | object | - | 图标文件复制配置 |
348
+
349
+ `Icon` 接口定义:
350
+
351
+ | 属性 | 类型 | 必填 | 描述 |
352
+ | ----- | ------ | ---- | -------------- |
353
+ | rel | string | 是 | 图标关系类型 |
354
+ | href | string | 是 | 图标 URL |
355
+ | sizes | string | 否 | 图标尺寸 |
356
+ | type | string | 否 | 图标 MIME 类型 |
357
+
358
+ `copyOptions` 接口定义:
359
+
360
+ | 属性 | 类型 | 必填 | 默认值 | 描述 |
361
+ | --------- | ------- | ---- | ------ | ---------------- |
362
+ | sourceDir | string | 是 | - | 图标源文件目录 |
363
+ | targetDir | string | 是 | - | 图标目标目录 |
364
+ | overwrite | boolean | 否 | true | 是否覆盖同名文件 |
365
+ | recursive | boolean | 否 | true | 是否递归复制 |
366
+
367
+ ## 子路径导出
368
+
369
+ 支持按需导入模块,减少打包体积:
370
+
371
+ ```typescript
372
+ // 完整导入
373
+ import { buildProgress, copyFile, BasePlugin, Logger } from '@meng-xi/vite-plugin'
374
+
375
+ // 按模块导入
376
+ import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin/factory'
377
+ import { Logger } from '@meng-xi/vite-plugin/logger'
378
+ import { buildProgress, copyFile, generateRouter } from '@meng-xi/vite-plugin/plugins'
379
+ import { Validator, readFileContent, writeFileContent } from '@meng-xi/vite-plugin/common'
380
+
381
+ // 类型导入(从子路径按需导入类型定义)
382
+ import type { PluginWithInstance, PluginFactory, BasePluginOptions } from '@meng-xi/vite-plugin/factory'
383
+ import type { BuildProgressOptions, GenerateVersionOptions, InjectIcoOptions, Icon } from '@meng-xi/vite-plugin/plugins'
384
+ import type { DateFormatOptions } from '@meng-xi/vite-plugin/common'
385
+ ```
386
+
387
+ ## 更新日志
388
+
389
+ 查看 [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
390
+
391
+ ## 贡献指南
392
+
393
+ 欢迎贡献代码!请按以下步骤操作:
394
+
395
+ 1. Fork 本项目
396
+ 2. 创建功能分支:`git checkout -b feature/your-feature`
397
+ 3. 提交变更:`git commit -m "feat: your feature description"`
398
+ 4. 推送分支:`git push origin feature/your-feature`
399
+ 5. 创建 Pull Request
400
+
401
+ ## License
402
+
403
+ [MIT](LICENSE)
@@ -1 +1 @@
1
- "use strict";const format=require("../shared/vite-plugin.BZsetDCm.cjs"),validation=require("../shared/vite-plugin.IGZeStMa.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.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;
1
+ "use strict";const format=require("../shared/vite-plugin.Ba9646wL.cjs"),validation=require("../shared/vite-plugin.IGZeStMa.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;
@@ -132,11 +132,19 @@ declare function copySourceToTarget(sourcePath: string, targetPath: string, opti
132
132
  * @throws 当写入过程中出现错误时抛出异常
133
133
  */
134
134
  declare function writeFileContent(filePath: string, content: string): Promise<void>;
135
+ /**
136
+ * 读取文件内容
137
+ * @param filePath 文件路径
138
+ * @returns 文件内容字符串
139
+ * @throws 当读取过程中出现错误时抛出异常
140
+ */
141
+ declare function readFileContent(filePath: string): Promise<string>;
135
142
  /**
136
143
  * 同步读取文件内容
137
144
  * @param filePath 文件路径
138
145
  * @returns 文件内容字符串
139
146
  * @throws 当读取过程中出现错误时抛出异常
147
+ * @deprecated 请使用异步版本 readFileContent
140
148
  */
141
149
  declare function readFileSync(filePath: string): string;
142
150
 
@@ -306,5 +314,5 @@ declare function stripJsonComments(jsonString: string): string;
306
314
  */
307
315
  declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
308
316
 
309
- export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
317
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
310
318
  export type { DateFormatOptions };
@@ -132,11 +132,19 @@ declare function copySourceToTarget(sourcePath: string, targetPath: string, opti
132
132
  * @throws 当写入过程中出现错误时抛出异常
133
133
  */
134
134
  declare function writeFileContent(filePath: string, content: string): Promise<void>;
135
+ /**
136
+ * 读取文件内容
137
+ * @param filePath 文件路径
138
+ * @returns 文件内容字符串
139
+ * @throws 当读取过程中出现错误时抛出异常
140
+ */
141
+ declare function readFileContent(filePath: string): Promise<string>;
135
142
  /**
136
143
  * 同步读取文件内容
137
144
  * @param filePath 文件路径
138
145
  * @returns 文件内容字符串
139
146
  * @throws 当读取过程中出现错误时抛出异常
147
+ * @deprecated 请使用异步版本 readFileContent
140
148
  */
141
149
  declare function readFileSync(filePath: string): string;
142
150
 
@@ -306,5 +314,5 @@ declare function stripJsonComments(jsonString: string): string;
306
314
  */
307
315
  declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
308
316
 
309
- export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
317
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
310
318
  export type { DateFormatOptions };