@meng-xi/vite-plugin 0.0.5 → 0.0.6
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-en.md +186 -25
- package/README.md +343 -182
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +9 -1
- package/dist/common/index.d.mts +9 -1
- package/dist/common/index.d.ts +9 -1
- package/dist/common/index.mjs +1 -1
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.d.cts +71 -6
- package/dist/factory/index.d.mts +71 -6
- package/dist/factory/index.d.ts +71 -6
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +1 -1
- package/dist/logger/index.cjs +1 -1
- package/dist/logger/index.d.cts +1 -1
- package/dist/logger/index.d.mts +1 -1
- package/dist/logger/index.d.ts +1 -1
- package/dist/logger/index.mjs +1 -1
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +82 -7
- package/dist/plugins/index.d.mts +82 -7
- package/dist/plugins/index.d.ts +82 -7
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/vite-plugin.B5wW4CiL.mjs +36 -0
- package/dist/shared/vite-plugin.Ba9646wL.cjs +1 -0
- package/dist/shared/vite-plugin.C3ejdBNf.mjs +1 -0
- package/dist/shared/{vite-plugin.B3PARlU9.d.cts → vite-plugin.CLr0ttuO.d.cts} +16 -0
- package/dist/shared/{vite-plugin.B3PARlU9.d.mts → vite-plugin.CLr0ttuO.d.mts} +16 -0
- package/dist/shared/{vite-plugin.B3PARlU9.d.ts → vite-plugin.CLr0ttuO.d.ts} +16 -0
- package/dist/shared/vite-plugin.CXlzkIgT.cjs +36 -0
- package/dist/shared/vite-plugin.CawoITTT.cjs +1 -0
- package/dist/shared/vite-plugin.DSb6XzBn.mjs +1 -0
- package/package.json +72 -72
- package/dist/shared/vite-plugin.BZsetDCm.cjs +0 -1
- package/dist/shared/vite-plugin.C7isVPKg.mjs +0 -1
- package/dist/shared/vite-plugin.CS9a5kjK.mjs +0 -36
- package/dist/shared/vite-plugin.CgnG5_UX.cjs +0 -36
- package/dist/shared/vite-plugin.DqWt65U-.cjs +0 -1
- package/dist/shared/vite-plugin.UkE7CdSe.d.cts +0 -43
- package/dist/shared/vite-plugin.UkE7CdSe.d.mts +0 -43
- package/dist/shared/vite-plugin.UkE7CdSe.d.ts +0 -43
- package/dist/shared/vite-plugin.YvjM8LxW.mjs +0 -1
package/README.md
CHANGED
|
@@ -1,182 +1,343 @@
|
|
|
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.
|
|
6
|
-
</a>
|
|
7
|
-
<br>
|
|
8
|
-
<h1>@meng-xi/vite-plugin</h1>
|
|
9
|
-
<p>一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架</p>
|
|
10
|
-
|
|
11
|
-
[](LICENSE) [](https://www.npmjs.com/package/@meng-xi/vite-plugin)
|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
</div>
|
|
15
|
-
|
|
16
|
-
## 特性
|
|
17
|
-
|
|
18
|
-
- **开箱即用** - 提供文件复制、路由生成、版本管理、图标注入等实用插件
|
|
19
|
-
- **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义插件
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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://www.npmjs.com/package/@meng-xi/vite-plugin)
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## 特性
|
|
17
|
+
|
|
18
|
+
- **开箱即用** - 提供文件复制、路由生成、版本管理、图标注入等实用插件
|
|
19
|
+
- **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义插件
|
|
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
|
+
```bash
|
|
32
|
+
# npm
|
|
33
|
+
npm install @meng-xi/vite-plugin -D
|
|
34
|
+
|
|
35
|
+
# yarn
|
|
36
|
+
yarn add @meng-xi/vite-plugin -D
|
|
37
|
+
|
|
38
|
+
# pnpm
|
|
39
|
+
pnpm add @meng-xi/vite-plugin -D
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 快速开始
|
|
43
|
+
|
|
44
|
+
### 使用内置插件
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { defineConfig } from 'vite'
|
|
48
|
+
import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
|
|
49
|
+
|
|
50
|
+
export default defineConfig({
|
|
51
|
+
plugins: [
|
|
52
|
+
// 复制文件
|
|
53
|
+
copyFile({
|
|
54
|
+
sourceDir: 'src/assets',
|
|
55
|
+
targetDir: 'dist/assets'
|
|
56
|
+
}),
|
|
57
|
+
|
|
58
|
+
// 生成路由配置(uni-app)
|
|
59
|
+
generateRouter({
|
|
60
|
+
pagesJsonPath: 'src/pages.json',
|
|
61
|
+
outputPath: 'src/router.config.ts'
|
|
62
|
+
}),
|
|
63
|
+
|
|
64
|
+
// 生成版本号
|
|
65
|
+
generateVersion({
|
|
66
|
+
format: 'datetime',
|
|
67
|
+
outputType: 'both'
|
|
68
|
+
}),
|
|
69
|
+
|
|
70
|
+
// 注入网站图标
|
|
71
|
+
injectIco({
|
|
72
|
+
base: '/assets'
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 访问插件实例
|
|
79
|
+
|
|
80
|
+
所有内置插件返回的对象包含 `pluginInstance` 属性,可访问插件内部状态:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import type { PluginWithInstance } from '@meng-xi/vite-plugin/factory'
|
|
84
|
+
import type { GenerateRouterOptions } from '@meng-xi/vite-plugin'
|
|
85
|
+
|
|
86
|
+
const routerPlugin = generateRouter({ watch: true }) as PluginWithInstance<GenerateRouterOptions>
|
|
87
|
+
|
|
88
|
+
// 通过 pluginInstance 访问插件内部
|
|
89
|
+
console.log(routerPlugin.pluginInstance?.options)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 开发自定义插件
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
|
|
96
|
+
import type { BasePluginOptions, PluginWithInstance } from '@meng-xi/vite-plugin/factory'
|
|
97
|
+
import type { Plugin } from 'vite'
|
|
98
|
+
|
|
99
|
+
interface MyPluginOptions extends BasePluginOptions {
|
|
100
|
+
path: string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class MyPlugin extends BasePlugin<MyPluginOptions> {
|
|
104
|
+
protected getDefaultOptions() {
|
|
105
|
+
return { path: './default' }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
protected validateOptions(): void {
|
|
109
|
+
this.validator.field('path').required().string().validate()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
protected getPluginName(): string {
|
|
113
|
+
return 'my-plugin'
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
protected addPluginHooks(plugin: Plugin): void {
|
|
117
|
+
plugin.buildStart = () => {
|
|
118
|
+
this.logger.info(`Plugin started with path: ${this.options.path}`)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
protected destroy(): void {
|
|
123
|
+
super.destroy()
|
|
124
|
+
// 自定义清理逻辑,如关闭连接、停止监听等
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const myPlugin = createPluginFactory(MyPlugin)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 插件开发框架
|
|
132
|
+
|
|
133
|
+
### BasePlugin 核心概念
|
|
134
|
+
|
|
135
|
+
`BasePlugin` 是所有插件的基类,提供了完整的生命周期管理和开发规范:
|
|
136
|
+
|
|
137
|
+
#### 生命周期
|
|
138
|
+
|
|
139
|
+
| 阶段 | 方法 | 说明 |
|
|
140
|
+
| -------- | ------------------ | -------------------------------------- |
|
|
141
|
+
| 初始化 | `constructor` | 合并配置、初始化日志和验证器 |
|
|
142
|
+
| 配置解析 | `onConfigResolved` | Vite 配置解析完成时调用 |
|
|
143
|
+
| 钩子注册 | `addPluginHooks` | 注册 Vite 插件钩子 |
|
|
144
|
+
| 销毁 | `destroy` | `closeBundle` 时自动调用,用于清理资源 |
|
|
145
|
+
|
|
146
|
+
#### 钩子自动组合
|
|
147
|
+
|
|
148
|
+
`toPlugin()` 方法会自动组合以下钩子:
|
|
149
|
+
|
|
150
|
+
- **configResolved** - 先执行基类的 `onConfigResolved`,再执行子类注册的钩子
|
|
151
|
+
- **closeBundle** - 先执行子类注册的钩子,再执行基类的 `destroy`
|
|
152
|
+
|
|
153
|
+
> 子类无需手动注册 `closeBundle` 钩子来清理资源,只需重写 `destroy()` 方法即可。
|
|
154
|
+
|
|
155
|
+
#### 必须实现的方法
|
|
156
|
+
|
|
157
|
+
| 方法 | 说明 |
|
|
158
|
+
| ------------------------ | ------------------ |
|
|
159
|
+
| `getPluginName()` | 返回插件名称 |
|
|
160
|
+
| `addPluginHooks(plugin)` | 添加 Vite 插件钩子 |
|
|
161
|
+
|
|
162
|
+
#### 可选重写的方法
|
|
163
|
+
|
|
164
|
+
| 方法 | 默认行为 | 说明 |
|
|
165
|
+
| -------------------------- | ----------- | ---------------------------------- |
|
|
166
|
+
| `getDefaultOptions()` | 返回 `{}` | 提供插件默认配置 |
|
|
167
|
+
| `validateOptions()` | 无验证 | 验证配置参数 |
|
|
168
|
+
| `getEnforce()` | `undefined` | 插件执行时机(`'pre'` / `'post'`) |
|
|
169
|
+
| `onConfigResolved(config)` | 存储配置 | 配置解析完成回调 |
|
|
170
|
+
| `destroy()` | 注销日志 | 插件销毁时的清理逻辑 |
|
|
171
|
+
|
|
172
|
+
#### 内置属性
|
|
173
|
+
|
|
174
|
+
| 属性 | 类型 | 说明 |
|
|
175
|
+
| ------------ | ------------------------ | ----------------- |
|
|
176
|
+
| `options` | `Required<T>` | 合并后的完整配置 |
|
|
177
|
+
| `logger` | `PluginLogger` | 插件日志记录器 |
|
|
178
|
+
| `validator` | `Validator<T>` | 配置验证器 |
|
|
179
|
+
| `viteConfig` | `ResolvedConfig \| null` | Vite 解析后的配置 |
|
|
180
|
+
|
|
181
|
+
#### 错误处理策略
|
|
182
|
+
|
|
183
|
+
通过 `errorStrategy` 配置项控制错误行为:
|
|
184
|
+
|
|
185
|
+
- `'throw'`(默认)- 记录错误并抛出异常,中断构建
|
|
186
|
+
- `'log'` - 记录错误但不抛出,继续执行
|
|
187
|
+
- `'ignore'` - 记录错误但不抛出,继续执行
|
|
188
|
+
|
|
189
|
+
使用 `safeExecute` / `safeExecuteSync` 包裹可能出错的操作:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const result = await this.safeExecute(async () => {
|
|
193
|
+
return await someAsyncOperation()
|
|
194
|
+
}, '执行异步操作')
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### createPluginFactory
|
|
198
|
+
|
|
199
|
+
创建插件工厂函数,支持选项标准化:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// 基本使用
|
|
203
|
+
const myPlugin = createPluginFactory(MyPlugin)
|
|
204
|
+
|
|
205
|
+
// 带标准化器(支持字符串简写配置)
|
|
206
|
+
const myPlugin = createPluginFactory(MyPlugin, opt => (typeof opt === 'string' ? { path: opt } : opt))
|
|
207
|
+
|
|
208
|
+
// 使用时支持简写
|
|
209
|
+
myPlugin('./custom-path')
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Logger
|
|
213
|
+
|
|
214
|
+
全局单例日志管理器,为每个插件提供独立的日志控制:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { Logger } from '@meng-xi/vite-plugin/logger'
|
|
218
|
+
|
|
219
|
+
// 创建日志记录器(通常由 BasePlugin 自动调用)
|
|
220
|
+
Logger.create({ name: 'my-plugin', enabled: true })
|
|
221
|
+
|
|
222
|
+
// 注销插件日志配置(插件销毁时自动调用)
|
|
223
|
+
Logger.unregister('my-plugin')
|
|
224
|
+
|
|
225
|
+
// 销毁单例(测试场景使用)
|
|
226
|
+
Logger.destroy()
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
日志输出格式:
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
ℹ️ [@meng-xi/vite-plugin:my-plugin] Info message
|
|
233
|
+
✅ [@meng-xi/vite-plugin:my-plugin] Success message
|
|
234
|
+
⚠️ [@meng-xi/vite-plugin:my-plugin] Warning message
|
|
235
|
+
❌ [@meng-xi/vite-plugin:my-plugin] Error message
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 内置插件
|
|
239
|
+
|
|
240
|
+
### copyFile
|
|
241
|
+
|
|
242
|
+
在 Vite 构建完成后复制文件或目录到指定位置。
|
|
243
|
+
|
|
244
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
245
|
+
| ----------- | ------- | ------ | -------------------- |
|
|
246
|
+
| sourceDir | string | - | 源目录路径(必填) |
|
|
247
|
+
| targetDir | string | - | 目标目录路径(必填) |
|
|
248
|
+
| overwrite | boolean | true | 是否覆盖现有文件 |
|
|
249
|
+
| recursive | boolean | true | 是否递归复制子目录 |
|
|
250
|
+
| incremental | boolean | true | 是否启用增量复制 |
|
|
251
|
+
|
|
252
|
+
### generateRouter
|
|
253
|
+
|
|
254
|
+
根据 uni-app 项目的 `pages.json` 自动生成路由配置文件。
|
|
255
|
+
|
|
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 的修改 |
|
|
268
|
+
|
|
269
|
+
### generateVersion
|
|
270
|
+
|
|
271
|
+
在 Vite 构建过程中自动生成版本号。
|
|
272
|
+
|
|
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 文件) |
|
|
285
|
+
|
|
286
|
+
### injectIco
|
|
287
|
+
|
|
288
|
+
在 Vite 构建过程中将网站图标链接注入到 HTML 文件的 head 中。
|
|
289
|
+
|
|
290
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
291
|
+
| ----------- | ------ | ------ | --------------------------- |
|
|
292
|
+
| base | string | '/' | 图标文件的基础路径 |
|
|
293
|
+
| url | string | - | 图标的完整 URL |
|
|
294
|
+
| link | string | - | 自定义完整的 link 标签 HTML |
|
|
295
|
+
| icons | Icon[] | - | 自定义图标数组 |
|
|
296
|
+
| copyOptions | object | - | 图标文件复制配置 |
|
|
297
|
+
|
|
298
|
+
`Icon` 接口定义:
|
|
299
|
+
|
|
300
|
+
| 属性 | 类型 | 必填 | 描述 |
|
|
301
|
+
| ----- | ------ | ---- | -------------- |
|
|
302
|
+
| rel | string | 是 | 图标关系类型 |
|
|
303
|
+
| href | string | 是 | 图标 URL |
|
|
304
|
+
| sizes | string | 否 | 图标尺寸 |
|
|
305
|
+
| type | string | 否 | 图标 MIME 类型 |
|
|
306
|
+
|
|
307
|
+
## 子路径导出
|
|
308
|
+
|
|
309
|
+
支持按需导入模块,减少打包体积:
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
// 完整导入
|
|
313
|
+
import { copyFile, BasePlugin, Logger } from '@meng-xi/vite-plugin'
|
|
314
|
+
|
|
315
|
+
// 按模块导入
|
|
316
|
+
import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin/factory'
|
|
317
|
+
import { Logger } from '@meng-xi/vite-plugin/logger'
|
|
318
|
+
import { copyFile, generateRouter } from '@meng-xi/vite-plugin/plugins'
|
|
319
|
+
import { Validator, readFileContent, writeFileContent } from '@meng-xi/vite-plugin/common'
|
|
320
|
+
|
|
321
|
+
// 类型导入(从子路径按需导入类型定义)
|
|
322
|
+
import type { PluginWithInstance, PluginFactory, BasePluginOptions } from '@meng-xi/vite-plugin/factory'
|
|
323
|
+
import type { GenerateVersionOptions, InjectIcoOptions, Icon } from '@meng-xi/vite-plugin/plugins'
|
|
324
|
+
import type { DateFormatOptions } from '@meng-xi/vite-plugin/common'
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## 更新日志
|
|
328
|
+
|
|
329
|
+
查看 [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
|
|
330
|
+
|
|
331
|
+
## 贡献指南
|
|
332
|
+
|
|
333
|
+
欢迎贡献代码!请按以下步骤操作:
|
|
334
|
+
|
|
335
|
+
1. Fork 本项目
|
|
336
|
+
2. 创建功能分支:`git checkout -b feature/your-feature`
|
|
337
|
+
3. 提交变更:`git commit -m "feat: your feature description"`
|
|
338
|
+
4. 推送分支:`git push origin feature/your-feature`
|
|
339
|
+
5. 创建 Pull Request
|
|
340
|
+
|
|
341
|
+
## License
|
|
342
|
+
|
|
343
|
+
[MIT](LICENSE)
|
package/dist/common/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const format=require("../shared/vite-plugin.
|
|
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;
|
package/dist/common/index.d.cts
CHANGED
|
@@ -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 };
|
package/dist/common/index.d.mts
CHANGED
|
@@ -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 };
|
package/dist/common/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/common/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
|
|
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";import"fs";import"path";import"crypto";
|
package/dist/factory/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const index=require("../shared/vite-plugin.
|
|
1
|
+
"use strict";const index=require("../shared/vite-plugin.CawoITTT.cjs");require("../logger/index.cjs"),require("fs"),require("path"),require("crypto"),require("../shared/vite-plugin.IGZeStMa.cjs"),exports.BasePlugin=index.BasePlugin,exports.createPluginFactory=index.createPluginFactory;
|