@meng-xi/vite-plugin 0.0.1 → 0.0.3

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 (53) hide show
  1. package/README-en.md +150 -0
  2. package/README.md +84 -138
  3. package/dist/common/index.cjs +1 -0
  4. package/dist/common/index.d.cts +109 -0
  5. package/dist/common/index.d.mts +109 -0
  6. package/dist/common/index.d.ts +109 -0
  7. package/dist/common/index.mjs +1 -0
  8. package/dist/factory/index.cjs +1 -0
  9. package/dist/factory/index.d.cts +260 -0
  10. package/dist/factory/index.d.mts +260 -0
  11. package/dist/factory/index.d.ts +260 -0
  12. package/dist/factory/index.mjs +1 -0
  13. package/dist/index.cjs +1 -3
  14. package/dist/index.d.cts +7 -282
  15. package/dist/index.d.mts +7 -282
  16. package/dist/index.d.ts +7 -282
  17. package/dist/index.mjs +1 -3
  18. package/dist/logger/index.cjs +1 -0
  19. package/dist/logger/index.d.cts +1 -0
  20. package/dist/logger/index.d.mts +1 -0
  21. package/dist/logger/index.d.ts +1 -0
  22. package/dist/logger/index.mjs +1 -0
  23. package/dist/plugins/index.cjs +1 -0
  24. package/dist/plugins/index.d.cts +210 -0
  25. package/dist/plugins/index.d.mts +210 -0
  26. package/dist/plugins/index.d.ts +210 -0
  27. package/dist/plugins/index.mjs +1 -0
  28. package/dist/shared/vite-plugin.B3PARlU9.d.cts +119 -0
  29. package/dist/shared/vite-plugin.B3PARlU9.d.mts +119 -0
  30. package/dist/shared/vite-plugin.B3PARlU9.d.ts +119 -0
  31. package/dist/shared/vite-plugin.BT1oHRKK.cjs +1 -0
  32. package/dist/shared/vite-plugin.BTKhc7n7.cjs +3 -0
  33. package/dist/shared/vite-plugin.BZqhBDYR.mjs +1 -0
  34. package/dist/shared/vite-plugin.Bn8mcCzy.cjs +3 -0
  35. package/dist/shared/vite-plugin.CY2ydccp.mjs +3 -0
  36. package/dist/shared/vite-plugin.CiHfwMiN.d.cts +91 -0
  37. package/dist/shared/vite-plugin.CiHfwMiN.d.mts +91 -0
  38. package/dist/shared/vite-plugin.CiHfwMiN.d.ts +91 -0
  39. package/dist/shared/vite-plugin.ClHiVXD6.mjs +1 -0
  40. package/dist/shared/vite-plugin.DSRKYuae.mjs +3 -0
  41. package/dist/shared/vite-plugin.DrSzERYS.cjs +1 -0
  42. package/dist/shared/vite-plugin.UkE7CdSe.d.cts +43 -0
  43. package/dist/shared/vite-plugin.UkE7CdSe.d.mts +43 -0
  44. package/dist/shared/vite-plugin.UkE7CdSe.d.ts +43 -0
  45. package/package.json +72 -57
  46. package/dist/plugins/copyFile/index.d.ts +0 -44
  47. package/dist/plugins/copyFile/index.mjs +0 -43
  48. package/dist/plugins/copyFile/type.d.ts +0 -47
  49. package/dist/plugins/copyFile/type.mjs +0 -0
  50. package/dist/plugins/injectIco/index.d.ts +0 -74
  51. package/dist/plugins/injectIco/index.mjs +0 -82
  52. package/dist/plugins/injectIco/type.d.ts +0 -115
  53. package/dist/plugins/injectIco/type.mjs +0 -0
@@ -0,0 +1,260 @@
1
+ import { ResolvedConfig, Plugin } from 'vite';
2
+ import { B as BasePluginOptions, O as OptionsNormalizer, P as PluginFactory } from '../shared/vite-plugin.UkE7CdSe.js';
3
+ import { P as PluginLogger, a as LoggerOptions } from '../shared/vite-plugin.B3PARlU9.js';
4
+ import { V as Validator } from '../shared/vite-plugin.CiHfwMiN.js';
5
+
6
+ /**
7
+ * 基础插件抽象类,提供插件开发的核心功能和生命周期管理
8
+ *
9
+ * @class BasePlugin
10
+ * @template T - 插件配置类型,必须继承自 BasePluginOptions
11
+ * @abstract
12
+ * @description 该类是所有插件的基类,提供了插件配置管理、日志记录、生命周期管理等核心功能
13
+ * @example
14
+ * ```typescript
15
+ * class MyPlugin extends BasePlugin<MyPluginOptions> {
16
+ * protected getPluginName() {
17
+ * return 'my-plugin'
18
+ * }
19
+ *
20
+ * protected addPluginHooks(plugin: Plugin) {
21
+ * // 添加插件钩子
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ declare abstract class BasePlugin<T extends BasePluginOptions = BasePluginOptions> {
27
+ /**
28
+ * 插件配置
29
+ *
30
+ * @protected
31
+ * @description 插件配置,包含插件的运行参数和选项
32
+ */
33
+ protected options: Required<T>;
34
+ /**
35
+ * 插件日志记录器
36
+ *
37
+ * @protected
38
+ * @description 插件日志记录器,用于记录插件运行时的日志信息
39
+ */
40
+ protected logger: PluginLogger;
41
+ /**
42
+ * 插件配置验证器
43
+ *
44
+ * @protected
45
+ * @description 插件配置验证器,用于验证插件配置参数是否符合要求
46
+ */
47
+ protected validator: Validator<T>;
48
+ /**
49
+ * Vite 配置
50
+ *
51
+ * @protected
52
+ * @description Vite 配置,包含 Vite 构建的运行参数和选项
53
+ */
54
+ protected viteConfig: ResolvedConfig | null;
55
+ /**
56
+ * 插件构造函数
57
+ *
58
+ * @param options 插件配置
59
+ * @param loggerConfig 日志配置,可选
60
+ *
61
+ * @protected
62
+ * @description 插件构造函数,初始化插件配置、日志记录器和验证插件参数
63
+ */
64
+ constructor(options: T, loggerConfig?: LoggerOptions);
65
+ /**
66
+ * 获取插件的默认配置选项
67
+ *
68
+ * @protected
69
+ * @abstract
70
+ * @returns {Partial<T>} 插件特定的默认配置
71
+ * @description 子类必须实现此方法,以提供插件特定的默认配置值
72
+ */
73
+ protected abstract getDefaultOptions(): Partial<T>;
74
+ /**
75
+ * 合并插件配置,将用户提供的配置与默认配置合并
76
+ *
77
+ * @protected
78
+ * @template T - 插件配置类型,必须继承自 BasePluginOptions
79
+ * @param {T} options - 用户提供的插件配置
80
+ * @returns {Required<T>} 合并后的完整插件配置,包含所有必填字段
81
+ * @description 将用户提供的配置与基础默认值、插件特定默认值进行深度合并,确保所有必填字段都有值
82
+ * @example
83
+ * ```typescript
84
+ * const userOptions = { enabled: false }
85
+ * const mergedOptions = this.mergeOptions(userOptions)
86
+ * // mergedOptions 将包含基础默认值和插件特定默认值
87
+ * ```
88
+ */
89
+ protected mergeOptions(options: T): Required<T>;
90
+ /**
91
+ * 初始化日志记录器
92
+ *
93
+ * @private
94
+ * @param {LoggerOptions} loggerConfig - 日志配置对象,可选
95
+ * @returns {PluginLogger} 插件日志代理对象,用于记录插件日志
96
+ * @description 使用单例 Logger 创建插件特定的日志代理对象
97
+ */
98
+ private initLogger;
99
+ /**
100
+ * 验证插件配置参数,确保配置符合要求
101
+ *
102
+ * @protected
103
+ * @virtual
104
+ * @returns {void} 无返回值
105
+ * @throws {Error} 如果配置参数无效,抛出包含错误信息的异常
106
+ * @description 该方法在插件初始化时被调用,用于验证插件配置的有效性。子类可以重写此方法以添加自定义验证逻辑
107
+ * @example
108
+ * ```typescript
109
+ * protected validateOptions(): void {
110
+ * if (!this.options.sourceDir) {
111
+ * throw new Error('sourceDir 是必填项')
112
+ * }
113
+ *
114
+ * if (!this.options.targetDir) {
115
+ * throw new Error('targetDir 是必填项')
116
+ * }
117
+ * }
118
+ * ```
119
+ */
120
+ protected validateOptions(): void;
121
+ /**
122
+ * 获取插件名称
123
+ *
124
+ * @protected
125
+ * @returns {string} 插件的名称,用于 Vite 插件系统识别
126
+ */
127
+ protected abstract getPluginName(): string;
128
+ /**
129
+ * 获取插件执行时机
130
+ *
131
+ * @protected
132
+ * @returns {Plugin['enforce']} 插件的执行时机,可选值为 'pre'、'post' 或 undefined
133
+ * @description 'post' 表示插件在 Vite 构建后期执行
134
+ */
135
+ protected getEnforce(): Plugin['enforce'];
136
+ /**
137
+ * 处理配置解析完成事件
138
+ *
139
+ * @param config 解析后的 Vite 配置
140
+ *
141
+ * @protected
142
+ * @description 处理 Vite 配置解析完成事件,将解析后的配置存储到插件实例中
143
+ */
144
+ protected onConfigResolved(config: ResolvedConfig): void;
145
+ /**
146
+ * 添加插件钩子到 Vite 插件对象
147
+ *
148
+ * @protected
149
+ * @abstract
150
+ * @param {Plugin} plugin - Vite 插件对象,用于添加钩子
151
+ * @returns {void} 无返回值
152
+ * @description 添加插件钩子到 Vite 插件对象,用于在构建过程中执行插件逻辑
153
+ */
154
+ protected abstract addPluginHooks(plugin: Plugin): void;
155
+ /**
156
+ * 安全执行同步函数,自动处理执行过程中可能出现的错误
157
+ *
158
+ * @protected
159
+ * @template T - 函数的返回值类型
160
+ * @param {() => T} fn - 要执行的同步函数
161
+ * @param {string} context - 执行上下文描述,用于错误日志记录
162
+ * @returns {T | undefined} 函数的执行结果,如果执行过程中发生错误,根据错误策略返回 undefined 或抛出错误
163
+ * @description 该方法封装了同步函数的执行,自动处理可能出现的错误,根据插件配置的 errorStrategy 决定如何处理错误
164
+ * @example
165
+ * ```typescript
166
+ * // 安全执行同步操作
167
+ * const result = this.safeExecuteSync(() => {
168
+ * return someSyncOperation()
169
+ * }, '执行同步操作')
170
+ *
171
+ * // 如果 someSyncOperation() 抛出错误,会根据 errorStrategy 处理
172
+ * ```
173
+ */
174
+ protected safeExecuteSync<T>(fn: () => T, context: string): T | undefined;
175
+ /**
176
+ * 安全执行异步函数,自动处理执行过程中可能出现的错误
177
+ *
178
+ * @protected
179
+ * @async
180
+ * @template T - 异步函数的返回值类型
181
+ * @param {() => Promise<T>} fn - 要执行的异步函数
182
+ * @param {string} context - 执行上下文描述,用于错误日志记录
183
+ * @returns {Promise<T | undefined>} 异步函数的执行结果,如果执行过程中发生错误,根据错误策略返回 undefined 或抛出错误
184
+ * @description 该方法封装了异步函数的执行,自动处理可能出现的错误,根据插件配置的 errorStrategy 决定如何处理错误
185
+ * @example
186
+ * ```typescript
187
+ * // 安全执行异步操作
188
+ * const result = await this.safeExecute(async () => {
189
+ * return await someAsyncOperation()
190
+ * }, '执行异步操作')
191
+ *
192
+ * // 如果 someAsyncOperation() 抛出错误,会根据 errorStrategy 处理
193
+ * ```
194
+ */
195
+ protected safeExecute<T>(fn: () => Promise<T>, context: string): Promise<T | undefined>;
196
+ /**
197
+ * 处理插件执行过程中出现的错误,根据配置的错误策略决定如何处理
198
+ *
199
+ * @protected
200
+ * @template T - 返回值类型,仅当错误策略为 'log' 或 'ignore' 时返回 undefined
201
+ * @param {unknown} error - 捕获到的错误对象
202
+ * @param {string} context - 错误发生的上下文描述,用于错误日志记录
203
+ * @returns {T | undefined} 当错误策略为 'log' 或 'ignore' 时返回 undefined,否则抛出错误
204
+ * @description 根据插件配置的 errorStrategy 处理错误:
205
+ * - 'throw': 记录错误日志并抛出错误,中断执行
206
+ * - 'log': 记录错误日志但不抛出错误,继续执行
207
+ * - 'ignore': 记录错误日志但不抛出错误,继续执行
208
+ * - 默认:记录错误日志并抛出错误
209
+ * @example
210
+ * ```typescript
211
+ * // 当 errorStrategy 为 'throw' 时
212
+ * this.handleError(new Error('测试错误'), '测试上下文') // 记录错误日志并抛出错误
213
+ *
214
+ * // 当 errorStrategy 为 'log' 时
215
+ * this.handleError(new Error('测试错误'), '测试上下文') // 记录错误日志并返回 undefined
216
+ * ```
217
+ */
218
+ protected handleError<T>(error: unknown, context: string): T | undefined;
219
+ /**
220
+ * 将插件实例转换为 Vite 插件对象,用于 Vite 构建系统
221
+ *
222
+ * @public
223
+ * @returns {Plugin} Vite 插件对象,包含插件名称、执行时机和各种钩子函数
224
+ * @description 该方法创建并返回一个符合 Vite 插件规范的对象,设置了插件的基本信息和 configResolved 钩子,然后调用 addPluginHooks 方法添加插件特定的钩子
225
+ * @example
226
+ * ```typescript
227
+ * // 创建插件实例
228
+ * const pluginInstance = new MyPlugin(options)
229
+ *
230
+ * // 转换为 Vite 插件
231
+ * const vitePlugin = pluginInstance.toPlugin()
232
+ *
233
+ * // 导出 Vite 插件
234
+ * export const myPlugin = vitePlugin
235
+ * ```
236
+ */
237
+ toPlugin(): Plugin;
238
+ }
239
+ /**
240
+ * 创建插件工厂函数,用于生成 Vite 插件实例
241
+ *
242
+ * @template T - 插件配置类型,必须继承自 BasePluginOptions
243
+ * @template P - 插件实例类型,必须继承自 BasePlugin<T>
244
+ * @template R - 原始配置类型
245
+ * @param {new (options: T, loggerConfig?: LoggerOptions) => P} PluginClass - 插件类构造函数
246
+ * @param {OptionsNormalizer<T, R>} [normalizer] - 选项标准化器,可选
247
+ * @returns {PluginFactory<T, R>} 插件工厂函数,接收插件配置并返回 Vite 插件实例
248
+ * @description 该函数创建一个插件工厂,用于生成 Vite 插件实例。工厂函数接收插件配置,支持可选的标准化器,创建插件实例,转换为 Vite 插件对象,并在插件对象上添加对原始插件实例的引用
249
+ * @example
250
+ * ```typescript
251
+ * // 基本使用
252
+ * const myPluginFactory = createPluginFactory(MyPlugin)
253
+ *
254
+ * // 带标准化器的使用(支持字符串或对象)
255
+ * const myPluginWithNormalizer = createPluginFactory(MyPlugin, (opt) => typeof opt === 'string' ? { path: opt } : opt)
256
+ * ```
257
+ */
258
+ declare function createPluginFactory<T extends BasePluginOptions, P extends BasePlugin<T>, R = T>(PluginClass: new (options: T, loggerConfig?: LoggerOptions) => P, normalizer?: OptionsNormalizer<T, R>): PluginFactory<T, R>;
259
+
260
+ export { BasePlugin, createPluginFactory };
@@ -0,0 +1 @@
1
+ export{B as BasePlugin,c as createPluginFactory}from"../shared/vite-plugin.ClHiVXD6.mjs";import"../logger/index.mjs";import"fs";import"path";import"../shared/vite-plugin.DSRKYuae.mjs";
package/dist/index.cjs CHANGED
@@ -1,3 +1 @@
1
- "use strict";const i=require("fs");function _interopDefaultCompat(u){return u&&typeof u=="object"&&"default"in u?u.default:u}const i__default=_interopDefaultCompat(i);async function checkSourceExists(u){try{await i__default.promises.access(u,i__default.constants.F_OK)}catch(r){const e=r;throw e.code==="ENOENT"?new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${u}`):e.code==="EACCES"?new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${u}`):new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function ensureTargetDir(u){try{await i__default.promises.mkdir(u,{recursive:!0})}catch(r){const e=r;throw e.code==="EACCES"?new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${u}`):new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function copySourceToTarget(u,r,e){try{await i__default.promises.cp(u,r,{recursive:e.recursive,force:e.overwrite})}catch(o){const F=o;throw F.code==="ENOENT"?new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u590D\u5236\u8FC7\u7A0B\u4E2D\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${u}`):F.code==="EACCES"?new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u590D\u5236\u8FC7\u7A0B\u4E2D\u6743\u9650\u4E0D\u8DB3\uFF0C\u65E0\u6CD5\u8BBF\u95EE\u6E90\u6587\u4EF6\u6216\u5199\u5165\u76EE\u6807\u76EE\u5F55 - ${u} -> ${r}`):F.code==="EPERM"?new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u590D\u5236\u8FC7\u7A0B\u4E2D\u64CD\u4F5C\u88AB\u62D2\u7EDD - ${u} -> ${r}`):new Error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u590D\u5236\u6587\u4EF6\u65F6\u51FA\u9519 - ${u} -> ${r}\uFF0C\u9519\u8BEF\uFF1A${F.message}`)}}function generateIconTags(u){const r=[];if(u.link)return r.push(u.link),r;if(u.icons&&u.icons.length>0)r.push(...u.icons.map(e=>{let o=`<link rel="${e.rel}" href="${e.href}"`;return e.sizes&&(o+=` sizes="${e.sizes}"`),e.type&&(o+=` type="${e.type}"`),o+=" />",o}));else if(u.url)r.push(`<link rel="icon" href="${u.url}" />`);else{const e=u.base||"/",o=e.endsWith("/")?`${e}favicon.ico`:`${e}/favicon.ico`;r.push(`<link rel="icon" href="${o}" />`)}return r}function copyFile(u){const{sourceDir:r,targetDir:e,overwrite:o=!0,recursive:F=!0,verbose:n=!0,enabled:t=!0}=u;return{name:"copy-file",enforce:"post",async writeBundle(){if(!t){n&&console.log(`\u2139 \u590D\u5236\u6587\u4EF6\u529F\u80FD\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6267\u884C\uFF1A\u4ECE ${r} \u5230 ${e}`);return}try{await checkSourceExists(r),await ensureTargetDir(e),await copySourceToTarget(r,e,{recursive:F,overwrite:o}),n&&console.log(`\u2705 \u590D\u5236\u6587\u4EF6\u6210\u529F\uFF1A\u4ECE ${r} \u5230 ${e}`)}catch(c){throw n&&(c instanceof Error?console.error(c.message):console.error(`\u274C \u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u672A\u77E5\u9519\u8BEF - ${r} -> ${e}`,c)),c}}}}function injectIco(u){const r=typeof u=="string"?{base:u}:u||{},{verbose:e=!0,enabled:o=!0}=r;return{name:"inject-ico",transformIndexHtml(F){if(!o)return e&&console.log("\u2139 inject-ico: \u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),F;const n=generateIconTags(r);if(n.length===0)return e&&console.log("\u2139 inject-ico: \u6CA1\u6709\u751F\u6210\u56FE\u6807\u6807\u7B7E\uFF0C\u8DF3\u8FC7\u6CE8\u5165"),F;let t=F;const c=t.indexOf("</head>");if(c!==-1){const s=n.join(`
2
- `)+`
3
- `;t=t.substring(0,c)+s+t.substring(c),e&&(console.log(`\u2705 inject-ico: \u6210\u529F\u6CE8\u5165 ${n.length} \u4E2A\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6`),n.forEach(E=>{console.log(` - ${E}`)}))}else e&&console.warn("\u26A0 inject-ico: \u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165");return t},async writeBundle(){if(!o){e&&console.log("\u2139 inject-ico: \u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6587\u4EF6\u590D\u5236");return}const{copyOptions:F}=r;if(!F)return;const{sourceDir:n,targetDir:t,overwrite:c=!0,recursive:s=!0}=F;try{await checkSourceExists(n),await ensureTargetDir(t),await copySourceToTarget(n,t,{recursive:s,overwrite:c}),e&&console.log(`\u2705 inject-ico: \u56FE\u6807\u6587\u4EF6\u590D\u5236\u6210\u529F\uFF1A\u4ECE ${n} \u5230 ${t}`)}catch(E){throw e&&(E instanceof Error?console.error(E.message):console.error(`\u274C inject-ico: \u56FE\u6807\u6587\u4EF6\u590D\u5236\u5931\u8D25\uFF1A\u672A\u77E5\u9519\u8BEF - ${n} -> ${t}`,E)),E}}}}exports.copyFile=copyFile,exports.injectIco=injectIco;
1
+ "use strict";const index=require("./shared/vite-plugin.DrSzERYS.cjs"),validation=require("./shared/vite-plugin.BTKhc7n7.cjs"),index$1=require("./shared/vite-plugin.BT1oHRKK.cjs"),logger_index=require("./logger/index.cjs"),index$2=require("./shared/vite-plugin.Bn8mcCzy.cjs");require("fs"),require("path"),exports.checkSourceExists=index.checkSourceExists,exports.copySourceToTarget=index.copySourceToTarget,exports.ensureTargetDir=index.ensureTargetDir,exports.readDirRecursive=index.readDirRecursive,exports.readFileSync=index.readFileSync,exports.shouldUpdateFile=index.shouldUpdateFile,exports.writeFileContent=index.writeFileContent,exports.Validator=validation.Validator,exports.deepMerge=validation.deepMerge,exports.BasePlugin=index$1.BasePlugin,exports.createPluginFactory=index$1.createPluginFactory,exports.Logger=logger_index.Logger,exports.copyFile=index$2.copyFile,exports.injectIco=index$2.injectIco;
package/dist/index.d.cts CHANGED
@@ -1,282 +1,7 @@
1
- import { Plugin } from 'vite';
2
-
3
- /**
4
- * 复制文件插件的配置选项接口
5
- *
6
- * @interface CopyFileOptions
7
- */
8
- interface CopyFileOptions {
9
- /**
10
- * 源文件目录的路径
11
- *
12
- * @example 'src/assets'
13
- */
14
- sourceDir: string;
15
- /**
16
- * 目标文件目录的路径
17
- *
18
- * @example 'dist/assets'
19
- */
20
- targetDir: string;
21
- /**
22
- * 是否覆盖同名文件
23
- *
24
- * @defaultValue true
25
- * @example false
26
- */
27
- overwrite?: boolean;
28
- /**
29
- * 是否支持递归复制
30
- *
31
- * @defaultValue true
32
- * @example false
33
- */
34
- recursive?: boolean;
35
- /**
36
- * 是否显示详细日志
37
- *
38
- * @defaultValue true
39
- * @example false
40
- */
41
- verbose?: boolean;
42
- /**
43
- * 是否启用复制功能
44
- *
45
- * @defaultValue true
46
- * @example false
47
- */
48
- enabled?: boolean;
49
- }
50
-
51
- /**
52
- * 复制文件插件
53
- *
54
- * @param options - 配置参数
55
- * @returns 一个 Vite 插件实例
56
- *
57
- * @example
58
- * ```typescript
59
- * // 基本使用
60
- * copyFile({
61
- * sourceDir: 'src/assets',
62
- * targetDir: 'dist/assets'
63
- * })
64
- *
65
- * // 自定义配置
66
- * copyFile({
67
- * sourceDir: 'src/static',
68
- * targetDir: 'dist/static',
69
- * overwrite: false,
70
- * verbose: true,
71
- * recursive: false
72
- * })
73
- *
74
- * // 根据环境启用
75
- * copyFile({
76
- * sourceDir: 'src/assets',
77
- * targetDir: 'dist/assets',
78
- * enabled: process.env.NODE_ENV === 'production'
79
- * })
80
- *
81
- * // 禁用复制功能
82
- * copyFile({
83
- * sourceDir: 'src/assets',
84
- * targetDir: 'dist/assets',
85
- * enabled: false
86
- * })
87
- * ```
88
- *
89
- * @remarks
90
- * 该插件会在 Vite 构建完成后执行,将指定源目录的所有文件和子目录复制到目标目录
91
- */
92
- declare function copyFile(options: CopyFileOptions): Plugin;
93
-
94
- /**
95
- * 图标配置项接口
96
- *
97
- * @interface Icon
98
- */
99
- interface Icon {
100
- /**
101
- * 图标关系类型
102
- */
103
- rel: string;
104
- /**
105
- * 图标 URL
106
- */
107
- href: string;
108
- /**
109
- * 图标尺寸
110
- */
111
- sizes?: string;
112
- /**
113
- * 图标 MIME 类型
114
- */
115
- type?: string;
116
- }
117
- /**
118
- * 图标文件复制配置选项接口
119
- *
120
- * @interface CopyOptions
121
- */
122
- interface CopyOptions {
123
- /**
124
- * 图标源文件目录,用于复制图标到打包目录
125
- *
126
- * @example 'src/assets/icons'
127
- */
128
- sourceDir: string;
129
- /**
130
- * 图标目标目录(打包目录),用于复制图标到打包目录
131
- *
132
- * @example 'dist/assets/icons'
133
- */
134
- targetDir: string;
135
- /**
136
- * 是否覆盖同名文件
137
- *
138
- * @defaultValue true
139
- * @example false
140
- */
141
- overwrite?: boolean;
142
- /**
143
- * 是否支持递归复制
144
- *
145
- * @defaultValue true
146
- * @example false
147
- */
148
- recursive?: boolean;
149
- }
150
- /**
151
- * 注入网站图标链接的配置选项接口
152
- *
153
- * @interface InjectIcoOptions
154
- */
155
- interface InjectIcoOptions {
156
- /**
157
- * 图标文件的基础路径,默认为根路径 `/`
158
- *
159
- * @defaultValue `/`
160
- * @example '/assets'
161
- */
162
- base?: string;
163
- /**
164
- * 图标的完整 URL,如果提供则优先使用(覆盖 base + favicon.ico)
165
- *
166
- * @example 'https://example.com/favicon.ico'
167
- */
168
- url?: string;
169
- /**
170
- * 自定义的完整 link 标签 HTML,如果提供则优先使用(覆盖 url 和 base)
171
- *
172
- * @example '<link rel="icon" href="/favicon.svg" type="image/svg+xml" />'
173
- */
174
- link?: string;
175
- /**
176
- * 自定义图标数组,支持多种图标格式和尺寸
177
- *
178
- * @example
179
- * [
180
- * { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
181
- * { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
182
- * { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
183
- * ]
184
- */
185
- icons?: Icon[];
186
- /**
187
- * 是否显示详细日志
188
- *
189
- * @defaultValue true
190
- * @example false
191
- */
192
- verbose?: boolean;
193
- /**
194
- * 是否启用图标注入和文件复制功能
195
- *
196
- * @defaultValue true
197
- * @example false
198
- */
199
- enabled?: boolean;
200
- /**
201
- * 图标文件复制配置选项
202
- *
203
- * @remarks
204
- * 当此对象存在时,才会开启图标文件复制功能
205
- */
206
- copyOptions?: CopyOptions;
207
- }
208
-
209
- /**
210
- * 注入网站图标链接到 HTML 文件的头部
211
- *
212
- * @param options - 配置选项(字符串时视为 base)
213
- * @returns 一个 Vite 插件实例,用于在构建过程中修改 HTML 文件
214
- *
215
- * @example
216
- * ```typescript
217
- * // 基本使用
218
- * injectIco({ base: '/assets' })
219
- *
220
- * // 自定义图标
221
- * injectIco({
222
- * icons: [
223
- * { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
224
- * { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
225
- * { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
226
- * ]
227
- * })
228
- *
229
- * // 带文件复制功能(适用于 uni-app 等框架)
230
- * injectIco({
231
- * base: '/assets',
232
- * copyOptions: {
233
- * sourceDir: 'src/assets/icons',
234
- * targetDir: 'dist/assets/icons'
235
- * }
236
- * })
237
- *
238
- * // 带完整复制配置的使用
239
- * injectIco({
240
- * base: '/assets',
241
- * copyOptions: {
242
- * sourceDir: 'src/assets/icons',
243
- * targetDir: 'dist/assets/icons',
244
- * overwrite: false,
245
- * recursive: true
246
- * }
247
- * })
248
- *
249
- * // 关闭日志输出
250
- * injectIco({
251
- * base: '/assets',
252
- * verbose: false,
253
- * copyOptions: {
254
- * sourceDir: 'src/assets/icons',
255
- * targetDir: 'dist/assets/icons'
256
- * }
257
- * })
258
- *
259
- * // 根据环境启用
260
- * injectIco({
261
- * base: '/assets',
262
- * enabled: process.env.NODE_ENV === 'production',
263
- * copyOptions: {
264
- * sourceDir: 'src/assets/icons',
265
- * targetDir: 'dist/assets/icons'
266
- * }
267
- * })
268
- *
269
- * // 禁用插件
270
- * injectIco({
271
- * base: '/assets',
272
- * enabled: false,
273
- * copyOptions: {
274
- * sourceDir: 'src/assets/icons',
275
- * targetDir: 'dist/assets/icons'
276
- * }
277
- * })
278
- * ```
279
- */
280
- declare function injectIco(options?: InjectIcoOptions | string): Plugin;
281
-
282
- export { copyFile, injectIco };
1
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent } from './common/index.cjs';
2
+ export { V as Validator } from './shared/vite-plugin.CiHfwMiN.cjs';
3
+ export { BasePlugin, createPluginFactory } from './factory/index.cjs';
4
+ export { L as Logger, P as PluginLogger } from './shared/vite-plugin.B3PARlU9.cjs';
5
+ export { copyFile, injectIco } from './plugins/index.cjs';
6
+ import 'vite';
7
+ import './shared/vite-plugin.UkE7CdSe.cjs';