@meng-xi/vite-plugin 0.0.1

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 ADDED
@@ -0,0 +1,138 @@
1
+ # @meng-xi/vite-plugin [![npm](https://img.shields.io/npm/v/@meng-xi/vite-plugin?color=blue)](https://www.npmjs.com/package/@meng-xi/vite-plugin) ![GitHub](https://img.shields.io/github/license/MengXi-Studio/vite-plugin?color=orange)
2
+
3
+ > - 这是一个为 Vite 提供实用插件的工具包,帮助开发者简化构建流程,提高开发效率。
4
+ > - 扩展 Vite 构建流程的功能,提供常见构建任务的自动化处理方案。
5
+ > - 所有插件都支持详细的配置选项,可根据项目需求自定义行为,满足不同场景的使用需求。
6
+ > - 插件提供错误处理机制,确保构建流程能捕获到错误,提高构建的可靠性。
7
+ > - 采用模块化设计,插件可以单独使用,也可以组合使用,灵活应对不同项目的需求。
8
+
9
+ ---
10
+
11
+ 开始阅读[文档](https://mengxi-studio.github.io/vite-plugin/)。
12
+
13
+ ## 快速入门
14
+
15
+ ### 安装
16
+
17
+ 使用包管理器安装 `@meng-xi/vite-plugin`:
18
+
19
+ ```bash
20
+ # 使用 npm
21
+ npm install @meng-xi/vite-plugin --save-dev
22
+
23
+ # 使用 yarn
24
+ yarn add @meng-xi/vite-plugin --save-dev
25
+
26
+ # 使用 pnpm
27
+ pnpm add @meng-xi/vite-plugin --save-dev
28
+ ```
29
+
30
+ ### 基本使用
31
+
32
+ 在 Vite 配置文件中引入并使用插件:
33
+
34
+ ```typescript
35
+ import { defineConfig } from 'vite'
36
+ import { copyFile, injectIco } from '@meng-xi/vite-plugin'
37
+
38
+ export default defineConfig({
39
+ plugins: [
40
+ // 复制文件插件
41
+ copyFile({
42
+ sourceDir: 'src/assets',
43
+ targetDir: 'dist/assets'
44
+ }),
45
+
46
+ // 注入图标插件
47
+ injectIco({
48
+ base: '/assets'
49
+ })
50
+ ]
51
+ })
52
+ ```
53
+
54
+ ### 全部引入
55
+
56
+ 也可以使用默认导入的方式全部引入:
57
+
58
+ ```typescript
59
+ import { defineConfig } from 'vite'
60
+ import vitePlugin from '@meng-xi/vite-plugin'
61
+
62
+ export default defineConfig({
63
+ plugins: [
64
+ // 复制文件插件
65
+ vitePlugin.copyFile({
66
+ sourceDir: 'src/assets',
67
+ targetDir: 'dist/assets'
68
+ }),
69
+
70
+ // 注入图标插件
71
+ vitePlugin.injectIco({
72
+ base: '/assets'
73
+ })
74
+ ]
75
+ })
76
+ ```
77
+
78
+ ## 插件详情
79
+
80
+ ### copyFile 插件
81
+
82
+ 用于在 Vite 构建完成后复制文件或目录到指定位置。
83
+
84
+ **配置选项**:
85
+
86
+ - `sourceDir`:源目录路径(必填)
87
+ - `targetDir`:目标目录路径(必填)
88
+ - `overwrite`:是否覆盖已存在的文件,默认为 `true`
89
+ - `recursive`:是否递归复制子目录,默认为 `true`
90
+ - `verbose`:是否输出详细日志,默认为 `true`
91
+ - `enabled`:是否启用插件,默认为 `true`
92
+
93
+ ### injectIco 插件
94
+
95
+ 用于在 Vite 构建过程中注入网站图标链接到 HTML 文件的头部。
96
+
97
+ **配置选项**:
98
+
99
+ - `base`:图标文件的基础路径
100
+ - `url`:图标的完整 URL
101
+ - `link`:自定义的完整 link 标签 HTML
102
+ - `icons`:自定义图标数组
103
+ - `verbose`:是否输出详细日志,默认为 `true`
104
+ - `enabled`:是否启用插件,默认为 `true`
105
+ - `copyOptions`:图标文件复制配置
106
+
107
+ ## 贡献
108
+
109
+ 欢迎为 `@meng-xi/vite-plugin` 贡献代码。以下是贡献代码的步骤:
110
+
111
+ 1. Fork 项目:在 GitHub 上 Fork 此项目。
112
+ 2. 克隆代码:将 Fork 后的项目克隆到您的本地机器。
113
+
114
+ ```bash
115
+ git clone https://github.com/your-username/vite-plugin.git
116
+ cd vite-plugin
117
+ ```
118
+
119
+ 3. 创建新分支:基于 `master` 分支创建一个新的功能分支。
120
+
121
+ ```bash
122
+ git checkout -b feature/your-feature
123
+ ```
124
+
125
+ 4. 提交变更:确保您的代码通过了测试,并使用清晰的提交消息提交您的变更。
126
+
127
+ ```bash
128
+ git add .
129
+ git commit -m "feat: add your feature description"
130
+ ```
131
+
132
+ 5. Push 变更:将您的本地分支推送到 GitHub。
133
+
134
+ ```bash
135
+ git push origin feature/your-feature
136
+ ```
137
+
138
+ 6. 创建 PR:在 GitHub 上创建一个 Pull Request,并等待审核。
package/dist/index.cjs ADDED
@@ -0,0 +1,3 @@
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;
@@ -0,0 +1,282 @@
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 };
@@ -0,0 +1,282 @@
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 };