@meng-xi/vite-plugin 0.0.6 → 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.
- package/README-en.md +404 -343
- package/README.md +95 -35
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +182 -2
- package/dist/plugins/index.d.mts +182 -2
- package/dist/plugins/index.d.ts +182 -2
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/vite-plugin.CIahO6bu.mjs +37 -0
- package/dist/shared/vite-plugin.DqgHJjxa.cjs +37 -0
- package/package.json +1 -1
- package/dist/shared/vite-plugin.B5wW4CiL.mjs +0 -36
- package/dist/shared/vite-plugin.CXlzkIgT.cjs +0 -36
package/README-en.md
CHANGED
|
@@ -1,343 +1,404 @@
|
|
|
1
|
-
**English** | [中文](./README.md)
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
<a href="https://github.com/MengXi-Studio/vite-plugin">
|
|
5
|
-
<img alt="MengXi Studio 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>A toolkit providing practical plugins for Vite, also a complete plugin development framework</p>
|
|
10
|
-
|
|
11
|
-
[](LICENSE) [](https://www.npmjs.com/package/@meng-xi/vite-plugin)
|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
</div>
|
|
15
|
-
|
|
16
|
-
## Features
|
|
17
|
-
|
|
18
|
-
- **Ready to Use** - Provides practical plugins
|
|
19
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
Logger
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
|
257
|
-
|
|
|
258
|
-
|
|
|
259
|
-
|
|
|
260
|
-
|
|
|
261
|
-
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
|
266
|
-
|
|
|
267
|
-
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
|
301
|
-
|
|
|
302
|
-
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
1
|
+
**English** | [中文](./README.md)
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://github.com/MengXi-Studio/vite-plugin">
|
|
5
|
+
<img alt="MengXi Studio 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>A toolkit providing practical plugins for Vite, also a complete plugin development framework</p>
|
|
10
|
+
|
|
11
|
+
[](LICENSE) [](https://www.npmjs.com/package/@meng-xi/vite-plugin)
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Ready to Use** - Provides five practical plugins - buildProgress, copyFile, generateRouter, generateVersion, injectIco - covering build progress display, file copying, router generation, version management, and icon
|
|
19
|
+
injection
|
|
20
|
+
- **Plugin Development Framework** - Exports core components like BasePlugin, Logger, Validator for building custom Vite plugins
|
|
21
|
+
- **Complete Lifecycle** - Supports initialization, config resolution, destroy lifecycle management with automatic hook composition
|
|
22
|
+
- **Type Safe** - Complete TypeScript type definitions with configuration validators ensuring parameter correctness
|
|
23
|
+
- **Flexible Configuration** - All plugins support detailed configuration to meet diverse scenario requirements
|
|
24
|
+
- **Safe Execution** - Built-in error handling strategies (throw / log / ignore) for unified exception management
|
|
25
|
+
|
|
26
|
+
## Documentation
|
|
27
|
+
|
|
28
|
+
View full documentation: [https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
::: code-group
|
|
33
|
+
|
|
34
|
+
```bash [npm]
|
|
35
|
+
npm install @meng-xi/vite-plugin -D
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```bash [yarn]
|
|
39
|
+
yarn add @meng-xi/vite-plugin -D
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```bash [pnpm]
|
|
43
|
+
pnpm add @meng-xi/vite-plugin -D
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
:::
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### Using Built-in Plugins
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { defineConfig } from 'vite'
|
|
54
|
+
import { buildProgress, copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
|
|
55
|
+
|
|
56
|
+
export default defineConfig({
|
|
57
|
+
plugins: [
|
|
58
|
+
// Build progress bar
|
|
59
|
+
buildProgress(),
|
|
60
|
+
|
|
61
|
+
// Copy files
|
|
62
|
+
copyFile({
|
|
63
|
+
sourceDir: 'src/assets',
|
|
64
|
+
targetDir: 'dist/assets'
|
|
65
|
+
}),
|
|
66
|
+
|
|
67
|
+
// Generate router config (uni-app)
|
|
68
|
+
generateRouter({
|
|
69
|
+
pagesJsonPath: 'src/pages.json',
|
|
70
|
+
outputPath: 'src/router.config.ts'
|
|
71
|
+
}),
|
|
72
|
+
|
|
73
|
+
// Generate version
|
|
74
|
+
generateVersion({
|
|
75
|
+
format: 'datetime',
|
|
76
|
+
outputType: 'both'
|
|
77
|
+
}),
|
|
78
|
+
|
|
79
|
+
// Inject website icon
|
|
80
|
+
injectIco({
|
|
81
|
+
base: '/assets'
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Accessing Plugin Instance
|
|
88
|
+
|
|
89
|
+
All built-in plugins return an object with a `pluginInstance` property for accessing internal state:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import type { PluginWithInstance } from '@meng-xi/vite-plugin/factory'
|
|
93
|
+
import type { GenerateRouterOptions } from '@meng-xi/vite-plugin'
|
|
94
|
+
|
|
95
|
+
const routerPlugin = generateRouter({ watch: true }) as PluginWithInstance<GenerateRouterOptions>
|
|
96
|
+
|
|
97
|
+
// Access plugin internals via pluginInstance
|
|
98
|
+
console.log(routerPlugin.pluginInstance?.options)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Developing Custom Plugins
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
|
|
105
|
+
import type { BasePluginOptions, PluginWithInstance } from '@meng-xi/vite-plugin/factory'
|
|
106
|
+
import type { Plugin } from 'vite'
|
|
107
|
+
|
|
108
|
+
interface MyPluginOptions extends BasePluginOptions {
|
|
109
|
+
path: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class MyPlugin extends BasePlugin<MyPluginOptions> {
|
|
113
|
+
protected getDefaultOptions() {
|
|
114
|
+
return { path: './default' }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected validateOptions(): void {
|
|
118
|
+
this.validator.field('path').required().string().validate()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
protected getPluginName(): string {
|
|
122
|
+
return 'my-plugin'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
protected addPluginHooks(plugin: Plugin): void {
|
|
126
|
+
plugin.buildStart = () => {
|
|
127
|
+
this.logger.info(`Plugin started with path: ${this.options.path}`)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected destroy(): void {
|
|
132
|
+
super.destroy()
|
|
133
|
+
// Custom cleanup logic, e.g. close connections, stop watchers
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const myPlugin = createPluginFactory(MyPlugin)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Plugin Development Framework
|
|
141
|
+
|
|
142
|
+
### BasePlugin Core Concepts
|
|
143
|
+
|
|
144
|
+
`BasePlugin` is the base class for all plugins, providing complete lifecycle management and development conventions:
|
|
145
|
+
|
|
146
|
+
#### Lifecycle
|
|
147
|
+
|
|
148
|
+
| Phase | Method | Description |
|
|
149
|
+
| ----------------- | ------------------ | -------------------------------------------------------------- |
|
|
150
|
+
| Initialization | `constructor` | Merge options, initialize logger and validator |
|
|
151
|
+
| Config Resolution | `onConfigResolved` | Called when Vite config is resolved |
|
|
152
|
+
| Hook Registration | `addPluginHooks` | Register Vite plugin hooks |
|
|
153
|
+
| Destroy | `destroy` | Automatically called during `closeBundle` for resource cleanup |
|
|
154
|
+
|
|
155
|
+
#### Automatic Hook Composition
|
|
156
|
+
|
|
157
|
+
The `toPlugin()` method automatically composes the following hooks:
|
|
158
|
+
|
|
159
|
+
- **configResolved** - Base class `onConfigResolved` runs first, then subclass hook
|
|
160
|
+
- **closeBundle** - Subclass hook runs first, then base class `destroy`
|
|
161
|
+
|
|
162
|
+
> Subclasses don't need to manually register `closeBundle` hooks for cleanup — just override the `destroy()` method.
|
|
163
|
+
|
|
164
|
+
#### Required Methods
|
|
165
|
+
|
|
166
|
+
| Method | Description |
|
|
167
|
+
| ------------------------ | --------------------- |
|
|
168
|
+
| `getPluginName()` | Return plugin name |
|
|
169
|
+
| `addPluginHooks(plugin)` | Add Vite plugin hooks |
|
|
170
|
+
|
|
171
|
+
#### Optional Methods
|
|
172
|
+
|
|
173
|
+
| Method | Default Behavior | Description |
|
|
174
|
+
| -------------------------- | ----------------- | ------------------------------------------- |
|
|
175
|
+
| `getDefaultOptions()` | Returns `{}` | Provide plugin default options |
|
|
176
|
+
| `validateOptions()` | No validation | Validate configuration parameters |
|
|
177
|
+
| `getEnforce()` | `undefined` | Plugin execution order (`'pre'` / `'post'`) |
|
|
178
|
+
| `onConfigResolved(config)` | Store config | Config resolved callback |
|
|
179
|
+
| `destroy()` | Unregister logger | Cleanup logic when plugin is destroyed |
|
|
180
|
+
|
|
181
|
+
#### Built-in Properties
|
|
182
|
+
|
|
183
|
+
| Property | Type | Description |
|
|
184
|
+
| ------------ | ------------------------ | ----------------------------- |
|
|
185
|
+
| `options` | `Required<T>` | Merged complete configuration |
|
|
186
|
+
| `logger` | `PluginLogger` | Plugin logger |
|
|
187
|
+
| `validator` | `Validator<T>` | Configuration validator |
|
|
188
|
+
| `viteConfig` | `ResolvedConfig \| null` | Resolved Vite configuration |
|
|
189
|
+
|
|
190
|
+
#### Error Handling Strategy
|
|
191
|
+
|
|
192
|
+
Control error behavior via the `errorStrategy` configuration option:
|
|
193
|
+
|
|
194
|
+
- `'throw'` (default) - Log error and throw exception, halting the build
|
|
195
|
+
- `'log'` - Log error but don't throw, continue execution
|
|
196
|
+
- `'ignore'` - Log error but don't throw, continue execution
|
|
197
|
+
|
|
198
|
+
Wrap error-prone operations with `safeExecute` / `safeExecuteSync`:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const result = await this.safeExecute(async () => {
|
|
202
|
+
return await someAsyncOperation()
|
|
203
|
+
}, 'Execute async operation')
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### createPluginFactory
|
|
207
|
+
|
|
208
|
+
Create plugin factory functions with optional normalizer support:
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// Basic usage
|
|
212
|
+
const myPlugin = createPluginFactory(MyPlugin)
|
|
213
|
+
|
|
214
|
+
// With normalizer (supports shorthand string config)
|
|
215
|
+
const myPlugin = createPluginFactory(MyPlugin, opt => (typeof opt === 'string' ? { path: opt } : opt))
|
|
216
|
+
|
|
217
|
+
// Usage with shorthand
|
|
218
|
+
myPlugin('./custom-path')
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Logger
|
|
222
|
+
|
|
223
|
+
Global singleton log manager providing independent log control for each plugin:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { Logger } from '@meng-xi/vite-plugin/logger'
|
|
227
|
+
|
|
228
|
+
// Create logger (usually called automatically by BasePlugin)
|
|
229
|
+
Logger.create({ name: 'my-plugin', enabled: true })
|
|
230
|
+
|
|
231
|
+
// Unregister plugin log config (automatically called on plugin destroy)
|
|
232
|
+
Logger.unregister('my-plugin')
|
|
233
|
+
|
|
234
|
+
// Destroy singleton (for test scenarios)
|
|
235
|
+
Logger.destroy()
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Log output format:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
ℹ️ [@meng-xi/vite-plugin:my-plugin] Info message
|
|
242
|
+
✅ [@meng-xi/vite-plugin:my-plugin] Success message
|
|
243
|
+
⚠️ [@meng-xi/vite-plugin:my-plugin] Warning message
|
|
244
|
+
❌ [@meng-xi/vite-plugin:my-plugin] Error message
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Built-in Plugins
|
|
248
|
+
|
|
249
|
+
### buildProgress
|
|
250
|
+
|
|
251
|
+
Display real-time build progress bar in terminal during Vite build, supporting three display formats.
|
|
252
|
+
|
|
253
|
+
| Option | Type | Default | Description |
|
|
254
|
+
| --------------- | ------------------------------------- | ------- | ---------------------------------------------------- |
|
|
255
|
+
| width | number | 30 | Progress bar width (characters) |
|
|
256
|
+
| format | `'bar'` \| `'spinner'` \| `'minimal'` | 'bar' | Progress bar display format |
|
|
257
|
+
| completeChar | string | '█' | Fill character for completed portion |
|
|
258
|
+
| incompleteChar | string | '░' | Fill character for incomplete portion |
|
|
259
|
+
| clearOnComplete | boolean | true | Whether to clear progress bar on build completion |
|
|
260
|
+
| showModuleName | boolean | true | Whether to show the currently processing module name |
|
|
261
|
+
| theme | [ProgressTheme](#progresstheme) | - | Custom color theme |
|
|
262
|
+
|
|
263
|
+
**ProgressTheme**
|
|
264
|
+
|
|
265
|
+
| Property | Type | Description |
|
|
266
|
+
| --------------- | -------------------------- | ------------------------ |
|
|
267
|
+
| completeColor | `(text: string) => string` | Completed portion color |
|
|
268
|
+
| incompleteColor | `(text: string) => string` | Incomplete portion color |
|
|
269
|
+
| percentageColor | `(text: string) => string` | Percentage number color |
|
|
270
|
+
| phaseColor | `(text: string) => string` | Phase label color |
|
|
271
|
+
| moduleColor | `(text: string) => string` | Module name color |
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
// Default bar format
|
|
275
|
+
buildProgress()
|
|
276
|
+
|
|
277
|
+
// Spinner format
|
|
278
|
+
buildProgress({ format: 'spinner' })
|
|
279
|
+
|
|
280
|
+
// Minimal format
|
|
281
|
+
buildProgress({ format: 'minimal' })
|
|
282
|
+
|
|
283
|
+
// Custom appearance
|
|
284
|
+
buildProgress({
|
|
285
|
+
width: 40,
|
|
286
|
+
completeChar: '■',
|
|
287
|
+
incompleteChar: '□',
|
|
288
|
+
clearOnComplete: false
|
|
289
|
+
})
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### copyFile
|
|
293
|
+
|
|
294
|
+
Copy files or directories to specified locations after Vite build is completed.
|
|
295
|
+
|
|
296
|
+
| Option | Type | Default | Description |
|
|
297
|
+
| ----------- | ------- | ------- | ------------------------------------------ |
|
|
298
|
+
| sourceDir | string | - | Source directory path (required) |
|
|
299
|
+
| targetDir | string | - | Target directory path (required) |
|
|
300
|
+
| overwrite | boolean | true | Whether to overwrite existing files |
|
|
301
|
+
| recursive | boolean | true | Whether to recursively copy subdirectories |
|
|
302
|
+
| incremental | boolean | true | Whether to enable incremental copying |
|
|
303
|
+
|
|
304
|
+
### generateRouter
|
|
305
|
+
|
|
306
|
+
Automatically generate router configuration files based on uni-app project's `pages.json`.
|
|
307
|
+
|
|
308
|
+
| Option | Type | Default | Description |
|
|
309
|
+
| -------------------- | --------------------------------------------------------- | ---------------------- | ------------------------------------------------ |
|
|
310
|
+
| pagesJsonPath | string | 'src/pages.json' | Path to pages.json file |
|
|
311
|
+
| outputPath | string | 'src/router.config.ts' | Output file path |
|
|
312
|
+
| outputFormat | `'ts'` \| `'js'` | 'ts' | Output file format |
|
|
313
|
+
| nameStrategy | `'path'` \| `'camelCase'` \| `'pascalCase'` \| `'custom'` | 'camelCase' | Route name strategy |
|
|
314
|
+
| customNameGenerator | `(path: string) => string` | - | Custom route name generator function |
|
|
315
|
+
| includeSubPackages | boolean | true | Whether to include sub-package routes |
|
|
316
|
+
| watch | boolean | true | Whether to watch changes and auto-regenerate |
|
|
317
|
+
| metaMapping | `Record<string, string>` | - | Mapping from page style fields to meta |
|
|
318
|
+
| exportTypes | boolean | true | Whether to export type definitions |
|
|
319
|
+
| preserveRouteChanges | boolean | true | Whether to preserve user modifications to routes |
|
|
320
|
+
|
|
321
|
+
### generateVersion
|
|
322
|
+
|
|
323
|
+
Automatically generate version numbers during the Vite build process.
|
|
324
|
+
|
|
325
|
+
| Option | Type | Default | Description |
|
|
326
|
+
| ------------ | --------------------------------------------------------------------------------- | ----------------- | ------------------------------ |
|
|
327
|
+
| format | `'timestamp'` \| `'date'` \| `'datetime'` \| `'semver'` \| `'hash'` \| `'custom'` | 'timestamp' | Version format |
|
|
328
|
+
| customFormat | string | - | Custom format template |
|
|
329
|
+
| semverBase | string | '1.0.0' | Semantic version base |
|
|
330
|
+
| outputType | `'file'` \| `'define'` \| `'both'` | 'file' | Output type |
|
|
331
|
+
| outputFile | string | 'version.json' | Output file path |
|
|
332
|
+
| defineName | string | '**APP_VERSION**' | Global variable name to inject |
|
|
333
|
+
| hashLength | number | 8 | Hash length (1-32) |
|
|
334
|
+
| prefix | string | - | Version number prefix |
|
|
335
|
+
| suffix | string | - | Version number suffix |
|
|
336
|
+
| extra | `Record<string, unknown>` | - | Extra info (JSON file only) |
|
|
337
|
+
|
|
338
|
+
### injectIco
|
|
339
|
+
|
|
340
|
+
Inject website icon links into the head of HTML files during the Vite build process.
|
|
341
|
+
|
|
342
|
+
| Option | Type | Default | Description |
|
|
343
|
+
| ----------- | ------ | ------- | ------------------------------- |
|
|
344
|
+
| base | string | '/' | Base path for icon files |
|
|
345
|
+
| url | string | - | Complete URL for the icon |
|
|
346
|
+
| link | string | - | Custom complete link tag HTML |
|
|
347
|
+
| icons | Icon[] | - | Custom icon array |
|
|
348
|
+
| copyOptions | object | - | Icon file copying configuration |
|
|
349
|
+
|
|
350
|
+
`Icon` interface definition:
|
|
351
|
+
|
|
352
|
+
| Property | Type | Required | Description |
|
|
353
|
+
| -------- | ------ | -------- | ------------------ |
|
|
354
|
+
| rel | string | Yes | Icon relation type |
|
|
355
|
+
| href | string | Yes | Icon URL |
|
|
356
|
+
| sizes | string | No | Icon sizes |
|
|
357
|
+
| type | string | No | Icon MIME type |
|
|
358
|
+
|
|
359
|
+
`copyOptions` interface definition:
|
|
360
|
+
|
|
361
|
+
| Property | Type | Required | Default | Description |
|
|
362
|
+
| --------- | ------- | -------- | ------- | --------------------------- |
|
|
363
|
+
| sourceDir | string | Yes | - | Icon source directory |
|
|
364
|
+
| targetDir | string | Yes | - | Icon target directory |
|
|
365
|
+
| overwrite | boolean | No | true | Whether to overwrite files |
|
|
366
|
+
| recursive | boolean | No | true | Whether to copy recursively |
|
|
367
|
+
|
|
368
|
+
## Sub-path Exports
|
|
369
|
+
|
|
370
|
+
Support importing modules on demand to reduce bundle size:
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
// Full import
|
|
374
|
+
import { buildProgress, copyFile, BasePlugin, Logger } from '@meng-xi/vite-plugin'
|
|
375
|
+
|
|
376
|
+
// Module-level import
|
|
377
|
+
import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin/factory'
|
|
378
|
+
import { Logger } from '@meng-xi/vite-plugin/logger'
|
|
379
|
+
import { buildProgress, copyFile, generateRouter } from '@meng-xi/vite-plugin/plugins'
|
|
380
|
+
import { Validator, readFileContent, writeFileContent } from '@meng-xi/vite-plugin/common'
|
|
381
|
+
|
|
382
|
+
// Type imports (on-demand type definitions from sub-paths)
|
|
383
|
+
import type { PluginWithInstance, PluginFactory, BasePluginOptions } from '@meng-xi/vite-plugin/factory'
|
|
384
|
+
import type { BuildProgressOptions, GenerateVersionOptions, InjectIcoOptions, Icon } from '@meng-xi/vite-plugin/plugins'
|
|
385
|
+
import type { DateFormatOptions } from '@meng-xi/vite-plugin/common'
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## Changelog
|
|
389
|
+
|
|
390
|
+
See [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
|
|
391
|
+
|
|
392
|
+
## Contributing
|
|
393
|
+
|
|
394
|
+
Contributions are welcome! Please follow these steps:
|
|
395
|
+
|
|
396
|
+
1. Fork the repository
|
|
397
|
+
2. Create a feature branch: `git checkout -b feature/your-feature`
|
|
398
|
+
3. Commit changes: `git commit -m "feat: your feature description"`
|
|
399
|
+
4. Push to branch: `git push origin feature/your-feature`
|
|
400
|
+
5. Create a Pull Request
|
|
401
|
+
|
|
402
|
+
## License
|
|
403
|
+
|
|
404
|
+
[MIT](LICENSE)
|