@meng-xi/vite-plugin 0.0.2 → 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 (45) hide show
  1. package/README-en.md +150 -150
  2. package/README.md +84 -84
  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 -5
  14. package/dist/index.d.cts +7 -241
  15. package/dist/index.d.mts +7 -241
  16. package/dist/index.d.ts +7 -241
  17. package/dist/index.mjs +1 -5
  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 -53
@@ -0,0 +1,210 @@
1
+ import { B as BasePluginOptions, P as PluginFactory } from '../shared/vite-plugin.UkE7CdSe.mjs';
2
+ import 'vite';
3
+
4
+ /**
5
+ * 复制文件插件的配置选项接口
6
+ *
7
+ * @interface CopyFileOptions
8
+ */
9
+ interface CopyFileOptions extends BasePluginOptions {
10
+ /**
11
+ * 源文件目录的路径
12
+ *
13
+ * @example 'src/assets'
14
+ */
15
+ sourceDir: string;
16
+ /**
17
+ * 目标文件目录的路径
18
+ *
19
+ * @example 'dist/assets'
20
+ */
21
+ targetDir: string;
22
+ /**
23
+ * 是否覆盖同名文件
24
+ *
25
+ * @default true
26
+ */
27
+ overwrite?: boolean;
28
+ /**
29
+ * 是否支持递归复制
30
+ *
31
+ * @default true
32
+ */
33
+ recursive?: boolean;
34
+ /**
35
+ * 是否启用增量复制
36
+ *
37
+ * @default true
38
+ */
39
+ incremental?: boolean;
40
+ }
41
+
42
+ /**
43
+ * 复制文件插件
44
+ *
45
+ * @param {CopyFileOptions} options - 插件配置选项
46
+ * @returns {Plugin} 一个 Vite 插件实例
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // 基本使用
51
+ * copyFile({
52
+ * sourceDir: 'src/assets',
53
+ * targetDir: 'dist/assets'
54
+ * })
55
+ *
56
+ * // 高级配置
57
+ * copyFile({
58
+ * sourceDir: 'src/static',
59
+ * targetDir: 'dist/static',
60
+ * overwrite: false,
61
+ * recursive: true,
62
+ * incremental: true,
63
+ * enabled: true,
64
+ * verbose: true,
65
+ * errorStrategy: 'throw'
66
+ * })
67
+ * ```
68
+ *
69
+ * @remarks
70
+ * 该插件会在 Vite 构建完成后执行,将指定源目录的所有文件和子目录复制到目标目录。
71
+ * 支持增量复制、递归复制和覆盖控制等功能。
72
+ */
73
+ declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
74
+
75
+ /**
76
+ * 图标配置项接口
77
+ *
78
+ * @interface Icon
79
+ */
80
+ interface Icon {
81
+ /**
82
+ * 图标关系类型
83
+ */
84
+ rel: string;
85
+ /**
86
+ * 图标 URL
87
+ */
88
+ href: string;
89
+ /**
90
+ * 图标尺寸
91
+ */
92
+ sizes?: string;
93
+ /**
94
+ * 图标 MIME 类型
95
+ */
96
+ type?: string;
97
+ }
98
+ /**
99
+ * 图标文件复制配置选项接口
100
+ *
101
+ * @interface CopyOptions
102
+ */
103
+ interface CopyOptions {
104
+ /**
105
+ * 图标源文件目录,用于复制图标到打包目录
106
+ *
107
+ * @example 'src/assets/icons'
108
+ */
109
+ sourceDir: string;
110
+ /**
111
+ * 图标目标目录(打包目录),用于复制图标到打包目录
112
+ *
113
+ * @example 'dist/assets/icons'
114
+ */
115
+ targetDir: string;
116
+ /**
117
+ * 是否覆盖同名文件
118
+ *
119
+ * @default true
120
+ */
121
+ overwrite?: boolean;
122
+ /**
123
+ * 是否支持递归复制
124
+ *
125
+ * @default true
126
+ */
127
+ recursive?: boolean;
128
+ }
129
+ /**
130
+ * 注入网站图标链接的配置选项接口
131
+ *
132
+ * @interface InjectIcoOptions
133
+ */
134
+ interface InjectIcoOptions extends BasePluginOptions {
135
+ /**
136
+ * 图标文件的基础路径,默认为根路径 '/'
137
+ *
138
+ * @default '/'
139
+ * @example '/assets'
140
+ */
141
+ base?: string;
142
+ /**
143
+ * 图标的完整 URL,如果提供则优先使用(覆盖 base + favicon.ico)
144
+ *
145
+ * @example 'https://example.com/favicon.ico'
146
+ */
147
+ url?: string;
148
+ /**
149
+ * 自定义的完整 link 标签 HTML,如果提供则优先使用(覆盖 url 和 base)
150
+ *
151
+ * @example '<link rel="icon" href="/favicon.svg" type="image/svg+xml" />'
152
+ */
153
+ link?: string;
154
+ /**
155
+ * 自定义图标数组,支持多种图标格式和尺寸
156
+ *
157
+ * @example
158
+ * [
159
+ * { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
160
+ * { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
161
+ * { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
162
+ * ]
163
+ */
164
+ icons?: Icon[];
165
+ /**
166
+ * 图标文件复制配置选项
167
+ *
168
+ * @remarks
169
+ * 当此对象存在时,才会开启图标文件复制功能
170
+ */
171
+ copyOptions?: CopyOptions;
172
+ }
173
+
174
+ /**
175
+ * 创建注入图标插件实例
176
+ *
177
+ * @export
178
+ * @param {string | InjectIcoOptions} [options] - 插件配置选项,可以是字符串形式的 base 路径或完整的配置对象
179
+ * @returns {Plugin} Vite 插件实例,用于在构建过程中注入图标链接到 HTML 文件
180
+ * @example
181
+ * ```typescript
182
+ * // 基本使用
183
+ * injectIco() // 使用默认配置
184
+ *
185
+ * // 使用字符串配置 base 路径
186
+ * injectIco('/assets')
187
+ *
188
+ * // 使用完整配置
189
+ * injectIco({
190
+ * base: '/assets',
191
+ * icons: [
192
+ * { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
193
+ * { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' }
194
+ * ],
195
+ * copyOptions: {
196
+ * sourceDir: 'src/assets/icons',
197
+ * targetDir: 'dist/assets/icons'
198
+ * }
199
+ * })
200
+ * ```
201
+ * @remarks
202
+ * 该函数创建并返回一个 Vite 插件实例,该实例会在构建过程中:
203
+ * 1. 将图标链接注入到 HTML 文件的 `<head>` 标签中
204
+ * 2. 如果配置了 copyOptions,将图标文件复制到目标目录
205
+ *
206
+ * 支持自定义图标链接、图标数组配置以及图标文件复制功能。
207
+ */
208
+ declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
209
+
210
+ export { copyFile, injectIco };
@@ -0,0 +1,210 @@
1
+ import { B as BasePluginOptions, P as PluginFactory } from '../shared/vite-plugin.UkE7CdSe.js';
2
+ import 'vite';
3
+
4
+ /**
5
+ * 复制文件插件的配置选项接口
6
+ *
7
+ * @interface CopyFileOptions
8
+ */
9
+ interface CopyFileOptions extends BasePluginOptions {
10
+ /**
11
+ * 源文件目录的路径
12
+ *
13
+ * @example 'src/assets'
14
+ */
15
+ sourceDir: string;
16
+ /**
17
+ * 目标文件目录的路径
18
+ *
19
+ * @example 'dist/assets'
20
+ */
21
+ targetDir: string;
22
+ /**
23
+ * 是否覆盖同名文件
24
+ *
25
+ * @default true
26
+ */
27
+ overwrite?: boolean;
28
+ /**
29
+ * 是否支持递归复制
30
+ *
31
+ * @default true
32
+ */
33
+ recursive?: boolean;
34
+ /**
35
+ * 是否启用增量复制
36
+ *
37
+ * @default true
38
+ */
39
+ incremental?: boolean;
40
+ }
41
+
42
+ /**
43
+ * 复制文件插件
44
+ *
45
+ * @param {CopyFileOptions} options - 插件配置选项
46
+ * @returns {Plugin} 一个 Vite 插件实例
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // 基本使用
51
+ * copyFile({
52
+ * sourceDir: 'src/assets',
53
+ * targetDir: 'dist/assets'
54
+ * })
55
+ *
56
+ * // 高级配置
57
+ * copyFile({
58
+ * sourceDir: 'src/static',
59
+ * targetDir: 'dist/static',
60
+ * overwrite: false,
61
+ * recursive: true,
62
+ * incremental: true,
63
+ * enabled: true,
64
+ * verbose: true,
65
+ * errorStrategy: 'throw'
66
+ * })
67
+ * ```
68
+ *
69
+ * @remarks
70
+ * 该插件会在 Vite 构建完成后执行,将指定源目录的所有文件和子目录复制到目标目录。
71
+ * 支持增量复制、递归复制和覆盖控制等功能。
72
+ */
73
+ declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
74
+
75
+ /**
76
+ * 图标配置项接口
77
+ *
78
+ * @interface Icon
79
+ */
80
+ interface Icon {
81
+ /**
82
+ * 图标关系类型
83
+ */
84
+ rel: string;
85
+ /**
86
+ * 图标 URL
87
+ */
88
+ href: string;
89
+ /**
90
+ * 图标尺寸
91
+ */
92
+ sizes?: string;
93
+ /**
94
+ * 图标 MIME 类型
95
+ */
96
+ type?: string;
97
+ }
98
+ /**
99
+ * 图标文件复制配置选项接口
100
+ *
101
+ * @interface CopyOptions
102
+ */
103
+ interface CopyOptions {
104
+ /**
105
+ * 图标源文件目录,用于复制图标到打包目录
106
+ *
107
+ * @example 'src/assets/icons'
108
+ */
109
+ sourceDir: string;
110
+ /**
111
+ * 图标目标目录(打包目录),用于复制图标到打包目录
112
+ *
113
+ * @example 'dist/assets/icons'
114
+ */
115
+ targetDir: string;
116
+ /**
117
+ * 是否覆盖同名文件
118
+ *
119
+ * @default true
120
+ */
121
+ overwrite?: boolean;
122
+ /**
123
+ * 是否支持递归复制
124
+ *
125
+ * @default true
126
+ */
127
+ recursive?: boolean;
128
+ }
129
+ /**
130
+ * 注入网站图标链接的配置选项接口
131
+ *
132
+ * @interface InjectIcoOptions
133
+ */
134
+ interface InjectIcoOptions extends BasePluginOptions {
135
+ /**
136
+ * 图标文件的基础路径,默认为根路径 '/'
137
+ *
138
+ * @default '/'
139
+ * @example '/assets'
140
+ */
141
+ base?: string;
142
+ /**
143
+ * 图标的完整 URL,如果提供则优先使用(覆盖 base + favicon.ico)
144
+ *
145
+ * @example 'https://example.com/favicon.ico'
146
+ */
147
+ url?: string;
148
+ /**
149
+ * 自定义的完整 link 标签 HTML,如果提供则优先使用(覆盖 url 和 base)
150
+ *
151
+ * @example '<link rel="icon" href="/favicon.svg" type="image/svg+xml" />'
152
+ */
153
+ link?: string;
154
+ /**
155
+ * 自定义图标数组,支持多种图标格式和尺寸
156
+ *
157
+ * @example
158
+ * [
159
+ * { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
160
+ * { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
161
+ * { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
162
+ * ]
163
+ */
164
+ icons?: Icon[];
165
+ /**
166
+ * 图标文件复制配置选项
167
+ *
168
+ * @remarks
169
+ * 当此对象存在时,才会开启图标文件复制功能
170
+ */
171
+ copyOptions?: CopyOptions;
172
+ }
173
+
174
+ /**
175
+ * 创建注入图标插件实例
176
+ *
177
+ * @export
178
+ * @param {string | InjectIcoOptions} [options] - 插件配置选项,可以是字符串形式的 base 路径或完整的配置对象
179
+ * @returns {Plugin} Vite 插件实例,用于在构建过程中注入图标链接到 HTML 文件
180
+ * @example
181
+ * ```typescript
182
+ * // 基本使用
183
+ * injectIco() // 使用默认配置
184
+ *
185
+ * // 使用字符串配置 base 路径
186
+ * injectIco('/assets')
187
+ *
188
+ * // 使用完整配置
189
+ * injectIco({
190
+ * base: '/assets',
191
+ * icons: [
192
+ * { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
193
+ * { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' }
194
+ * ],
195
+ * copyOptions: {
196
+ * sourceDir: 'src/assets/icons',
197
+ * targetDir: 'dist/assets/icons'
198
+ * }
199
+ * })
200
+ * ```
201
+ * @remarks
202
+ * 该函数创建并返回一个 Vite 插件实例,该实例会在构建过程中:
203
+ * 1. 将图标链接注入到 HTML 文件的 `<head>` 标签中
204
+ * 2. 如果配置了 copyOptions,将图标文件复制到目标目录
205
+ *
206
+ * 支持自定义图标链接、图标数组配置以及图标文件复制功能。
207
+ */
208
+ declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
209
+
210
+ export { copyFile, injectIco };
@@ -0,0 +1 @@
1
+ export{c as copyFile,i as injectIco}from"../shared/vite-plugin.CY2ydccp.mjs";import"../shared/vite-plugin.ClHiVXD6.mjs";import"../logger/index.mjs";import"fs";import"path";import"../shared/vite-plugin.DSRKYuae.mjs";import"../shared/vite-plugin.BZqhBDYR.mjs";
@@ -0,0 +1,119 @@
1
+ /**
2
+ * 构造函数参数接口
3
+ */
4
+ interface LoggerOptions {
5
+ /**
6
+ * 插件名称
7
+ */
8
+ name: string;
9
+ /**
10
+ * 是否启用日志
11
+ */
12
+ enabled?: boolean;
13
+ }
14
+
15
+ /**
16
+ * 日志工具类(单例模式)
17
+ * @description 全局单例日志管理器,统一管理所有插件的日志输出
18
+ */
19
+ declare class Logger {
20
+ /**
21
+ * 单例实例
22
+ */
23
+ private static instance;
24
+ /**
25
+ * 库名称
26
+ */
27
+ private readonly libName;
28
+ /**
29
+ * 插件日志配置映射表
30
+ * @description 存储每个插件的日志开关状态
31
+ */
32
+ private pluginConfigs;
33
+ /**
34
+ * 日志类型映射
35
+ */
36
+ private readonly logTypes;
37
+ /**
38
+ * 私有构造函数,防止外部实例化
39
+ */
40
+ private constructor();
41
+ /**
42
+ * 获取单例实例
43
+ * @returns Logger 单例实例
44
+ */
45
+ private static getInstance;
46
+ /**
47
+ * 创建日志记录器(工厂方法)
48
+ * @param options 配置选项
49
+ * @returns Logger 单例实例
50
+ * @description 为插件创建日志记录器,实际返回单例实例并注册插件配置
51
+ */
52
+ static create(options: LoggerOptions): Logger;
53
+ /**
54
+ * 注册插件日志配置
55
+ * @param pluginName 插件名称
56
+ * @param enabled 是否启用日志
57
+ */
58
+ private registerPlugin;
59
+ /**
60
+ * 生成日志前缀
61
+ * @param pluginName 插件名称
62
+ * @returns 格式化的日志前缀
63
+ */
64
+ private formatPrefix;
65
+ /**
66
+ * 检查插件日志是否启用
67
+ * @param pluginName 插件名称
68
+ * @returns 是否启用
69
+ */
70
+ private isPluginEnabled;
71
+ /**
72
+ * 统一日志输出方法
73
+ * @param pluginName 插件名称
74
+ * @param type 日志类型
75
+ * @param message 日志消息
76
+ * @param data 附加数据
77
+ */
78
+ private log;
79
+ /**
80
+ * 创建插件日志代理对象
81
+ * @param pluginName 插件名称
82
+ * @returns 插件日志代理对象
83
+ * @internal 供 BasePlugin 内部使用
84
+ */
85
+ createPluginLogger(pluginName: string): PluginLogger;
86
+ }
87
+ /**
88
+ * 插件日志代理接口
89
+ * @description 为每个插件提供独立的日志接口
90
+ */
91
+ interface PluginLogger {
92
+ /**
93
+ * 输出成功日志
94
+ * @param message 日志消息
95
+ * @param data 附加数据
96
+ */
97
+ success(message: string, data?: any): void;
98
+ /**
99
+ * 输出信息日志
100
+ * @param message 日志消息
101
+ * @param data 附加数据
102
+ */
103
+ info(message: string, data?: any): void;
104
+ /**
105
+ * 输出警告日志
106
+ * @param message 日志消息
107
+ * @param data 附加数据
108
+ */
109
+ warn(message: string, data?: any): void;
110
+ /**
111
+ * 输出错误日志
112
+ * @param message 日志消息
113
+ * @param data 附加数据
114
+ */
115
+ error(message: string, data?: any): void;
116
+ }
117
+
118
+ export { Logger as L };
119
+ export type { PluginLogger as P, LoggerOptions as a };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * 构造函数参数接口
3
+ */
4
+ interface LoggerOptions {
5
+ /**
6
+ * 插件名称
7
+ */
8
+ name: string;
9
+ /**
10
+ * 是否启用日志
11
+ */
12
+ enabled?: boolean;
13
+ }
14
+
15
+ /**
16
+ * 日志工具类(单例模式)
17
+ * @description 全局单例日志管理器,统一管理所有插件的日志输出
18
+ */
19
+ declare class Logger {
20
+ /**
21
+ * 单例实例
22
+ */
23
+ private static instance;
24
+ /**
25
+ * 库名称
26
+ */
27
+ private readonly libName;
28
+ /**
29
+ * 插件日志配置映射表
30
+ * @description 存储每个插件的日志开关状态
31
+ */
32
+ private pluginConfigs;
33
+ /**
34
+ * 日志类型映射
35
+ */
36
+ private readonly logTypes;
37
+ /**
38
+ * 私有构造函数,防止外部实例化
39
+ */
40
+ private constructor();
41
+ /**
42
+ * 获取单例实例
43
+ * @returns Logger 单例实例
44
+ */
45
+ private static getInstance;
46
+ /**
47
+ * 创建日志记录器(工厂方法)
48
+ * @param options 配置选项
49
+ * @returns Logger 单例实例
50
+ * @description 为插件创建日志记录器,实际返回单例实例并注册插件配置
51
+ */
52
+ static create(options: LoggerOptions): Logger;
53
+ /**
54
+ * 注册插件日志配置
55
+ * @param pluginName 插件名称
56
+ * @param enabled 是否启用日志
57
+ */
58
+ private registerPlugin;
59
+ /**
60
+ * 生成日志前缀
61
+ * @param pluginName 插件名称
62
+ * @returns 格式化的日志前缀
63
+ */
64
+ private formatPrefix;
65
+ /**
66
+ * 检查插件日志是否启用
67
+ * @param pluginName 插件名称
68
+ * @returns 是否启用
69
+ */
70
+ private isPluginEnabled;
71
+ /**
72
+ * 统一日志输出方法
73
+ * @param pluginName 插件名称
74
+ * @param type 日志类型
75
+ * @param message 日志消息
76
+ * @param data 附加数据
77
+ */
78
+ private log;
79
+ /**
80
+ * 创建插件日志代理对象
81
+ * @param pluginName 插件名称
82
+ * @returns 插件日志代理对象
83
+ * @internal 供 BasePlugin 内部使用
84
+ */
85
+ createPluginLogger(pluginName: string): PluginLogger;
86
+ }
87
+ /**
88
+ * 插件日志代理接口
89
+ * @description 为每个插件提供独立的日志接口
90
+ */
91
+ interface PluginLogger {
92
+ /**
93
+ * 输出成功日志
94
+ * @param message 日志消息
95
+ * @param data 附加数据
96
+ */
97
+ success(message: string, data?: any): void;
98
+ /**
99
+ * 输出信息日志
100
+ * @param message 日志消息
101
+ * @param data 附加数据
102
+ */
103
+ info(message: string, data?: any): void;
104
+ /**
105
+ * 输出警告日志
106
+ * @param message 日志消息
107
+ * @param data 附加数据
108
+ */
109
+ warn(message: string, data?: any): void;
110
+ /**
111
+ * 输出错误日志
112
+ * @param message 日志消息
113
+ * @param data 附加数据
114
+ */
115
+ error(message: string, data?: any): void;
116
+ }
117
+
118
+ export { Logger as L };
119
+ export type { PluginLogger as P, LoggerOptions as a };