@meng-xi/vite-plugin 0.0.5 → 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.
Files changed (46) hide show
  1. package/README-en.md +404 -182
  2. package/README.md +403 -182
  3. package/dist/common/index.cjs +1 -1
  4. package/dist/common/index.d.cts +9 -1
  5. package/dist/common/index.d.mts +9 -1
  6. package/dist/common/index.d.ts +9 -1
  7. package/dist/common/index.mjs +1 -1
  8. package/dist/factory/index.cjs +1 -1
  9. package/dist/factory/index.d.cts +71 -6
  10. package/dist/factory/index.d.mts +71 -6
  11. package/dist/factory/index.d.ts +71 -6
  12. package/dist/factory/index.mjs +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +4 -5
  15. package/dist/index.d.mts +4 -5
  16. package/dist/index.d.ts +4 -5
  17. package/dist/index.mjs +1 -1
  18. package/dist/logger/index.cjs +1 -1
  19. package/dist/logger/index.d.cts +1 -1
  20. package/dist/logger/index.d.mts +1 -1
  21. package/dist/logger/index.d.ts +1 -1
  22. package/dist/logger/index.mjs +1 -1
  23. package/dist/plugins/index.cjs +1 -1
  24. package/dist/plugins/index.d.cts +263 -8
  25. package/dist/plugins/index.d.mts +263 -8
  26. package/dist/plugins/index.d.ts +263 -8
  27. package/dist/plugins/index.mjs +1 -1
  28. package/dist/shared/vite-plugin.Ba9646wL.cjs +1 -0
  29. package/dist/shared/vite-plugin.C3ejdBNf.mjs +1 -0
  30. package/dist/shared/vite-plugin.CIahO6bu.mjs +37 -0
  31. package/dist/shared/{vite-plugin.B3PARlU9.d.cts → vite-plugin.CLr0ttuO.d.cts} +16 -0
  32. package/dist/shared/{vite-plugin.B3PARlU9.d.mts → vite-plugin.CLr0ttuO.d.mts} +16 -0
  33. package/dist/shared/{vite-plugin.B3PARlU9.d.ts → vite-plugin.CLr0ttuO.d.ts} +16 -0
  34. package/dist/shared/vite-plugin.CawoITTT.cjs +1 -0
  35. package/dist/shared/vite-plugin.DSb6XzBn.mjs +1 -0
  36. package/dist/shared/vite-plugin.DqgHJjxa.cjs +37 -0
  37. package/package.json +72 -72
  38. package/dist/shared/vite-plugin.BZsetDCm.cjs +0 -1
  39. package/dist/shared/vite-plugin.C7isVPKg.mjs +0 -1
  40. package/dist/shared/vite-plugin.CS9a5kjK.mjs +0 -36
  41. package/dist/shared/vite-plugin.CgnG5_UX.cjs +0 -36
  42. package/dist/shared/vite-plugin.DqWt65U-.cjs +0 -1
  43. package/dist/shared/vite-plugin.UkE7CdSe.d.cts +0 -43
  44. package/dist/shared/vite-plugin.UkE7CdSe.d.mts +0 -43
  45. package/dist/shared/vite-plugin.UkE7CdSe.d.ts +0 -43
  46. package/dist/shared/vite-plugin.YvjM8LxW.mjs +0 -1
package/README-en.md CHANGED
@@ -1,182 +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.svg">
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://img.shields.io/github/license/MengXi-Studio/vite-plugin.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@meng-xi/vite-plugin?color=blue)](https://www.npmjs.com/package/@meng-xi/vite-plugin)
12
- ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
13
-
14
- </div>
15
-
16
- ## Features
17
-
18
- - **Ready to Use** - Provides practical plugins for file copying, router generation, version management, icon injection
19
- - **Plugin Development Framework** - Exports core components like BasePlugin, Logger, Validator for building custom plugins
20
- - **Type Safe** - Complete TypeScript type definitions with configuration validators ensuring parameter correctness
21
- - **Flexible Configuration** - All plugins support detailed configuration to meet diverse scenario requirements
22
-
23
- ## Documentation
24
-
25
- View full documentation: [https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
26
-
27
- ## Installation
28
-
29
- ```bash
30
- # npm
31
- npm install @meng-xi/vite-plugin -D
32
-
33
- # yarn
34
- yarn add @meng-xi/vite-plugin -D
35
-
36
- # pnpm
37
- pnpm add @meng-xi/vite-plugin -D
38
- ```
39
-
40
- ## Quick Start
41
-
42
- ### Using Built-in Plugins
43
-
44
- ```typescript
45
- import { defineConfig } from 'vite'
46
- import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
47
-
48
- export default defineConfig({
49
- plugins: [
50
- // Copy files
51
- copyFile({
52
- sourceDir: 'src/assets',
53
- targetDir: 'dist/assets'
54
- }),
55
-
56
- // Generate router config (uni-app)
57
- generateRouter({
58
- pagesJsonPath: 'src/pages.json',
59
- outputPath: 'src/router.config.ts'
60
- }),
61
-
62
- // Generate version
63
- generateVersion({
64
- format: 'datetime',
65
- outputType: 'both'
66
- }),
67
-
68
- // Inject website icon
69
- injectIco({
70
- base: '/assets'
71
- })
72
- ]
73
- })
74
- ```
75
-
76
- ### Developing Custom Plugins
77
-
78
- ```typescript
79
- import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
80
- import type { Plugin } from 'vite'
81
-
82
- interface MyPluginOptions {
83
- path: string
84
- enabled?: boolean
85
- verbose?: boolean
86
- errorStrategy?: 'throw' | 'log' | 'ignore'
87
- }
88
-
89
- class MyPlugin extends BasePlugin<MyPluginOptions> {
90
- protected getDefaultOptions() {
91
- return { path: './default' }
92
- }
93
-
94
- protected validateOptions(): void {
95
- this.validator.field('path').required().string().validate()
96
- }
97
-
98
- protected getPluginName(): string {
99
- return 'my-plugin'
100
- }
101
-
102
- protected addPluginHooks(plugin: Plugin): void {
103
- plugin.buildStart = () => {
104
- this.logger.info(`Plugin started with path: ${this.options.path}`)
105
- }
106
- }
107
- }
108
-
109
- export const myPlugin = createPluginFactory(MyPlugin)
110
- ```
111
-
112
- ## Built-in Plugins
113
-
114
- ### copyFile
115
-
116
- Copy files or directories to specified locations after Vite build is completed.
117
-
118
- | Option | Type | Default | Description |
119
- | ----------- | ------- | ------- | ------------------------------------------ |
120
- | sourceDir | string | - | Source directory path (required) |
121
- | targetDir | string | - | Target directory path (required) |
122
- | overwrite | boolean | true | Whether to overwrite existing files |
123
- | recursive | boolean | true | Whether to recursively copy subdirectories |
124
- | incremental | boolean | true | Whether to enable incremental copying |
125
-
126
- ### generateRouter
127
-
128
- Automatically generate router configuration files based on uni-app project's `pages.json`.
129
-
130
- | Option | Type | Default | Description |
131
- | -------------------- | ------------ | ---------------------- | ------------------------------------------------ |
132
- | pagesJsonPath | string | 'src/pages.json' | Path to pages.json file |
133
- | outputPath | string | 'src/router.config.ts' | Output file path |
134
- | outputFormat | 'ts' \| 'js' | 'ts' | Output file format |
135
- | nameStrategy | string | 'camelCase' | Route name strategy |
136
- | includeSubPackages | boolean | true | Whether to include sub-package routes |
137
- | watch | boolean | true | Whether to watch changes and auto-regenerate |
138
- | metaMapping | object | - | Mapping from page style fields to meta |
139
- | preserveRouteChanges | boolean | true | Whether to preserve user modifications to routes |
140
-
141
- ### generateVersion
142
-
143
- Automatically generate version numbers during the Vite build process.
144
-
145
- | Option | Type | Default | Description |
146
- | ---------- | ------ | --------------------- | ------------------------------ |
147
- | format | string | 'timestamp' | Version format |
148
- | outputType | string | 'file' | Output type |
149
- | outputFile | string | 'version.json' | Output file path |
150
- | defineName | string | '\_\_APP_VERSION\_\_' | Global variable name to inject |
151
- | prefix | string | - | Version number prefix |
152
- | suffix | string | - | Version number suffix |
153
-
154
- ### injectIco
155
-
156
- Inject website icon links into the head of HTML files during the Vite build process.
157
-
158
- | Option | Type | Default | Description |
159
- | ----------- | ------ | ------- | ------------------------------- |
160
- | base | string | - | Base path for icon files |
161
- | url | string | - | Complete URL for the icon |
162
- | link | string | - | Custom complete link tag HTML |
163
- | icons | array | - | Custom icon array |
164
- | copyOptions | object | - | Icon file copying configuration |
165
-
166
- ## Changelog
167
-
168
- See [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
169
-
170
- ## Contributing
171
-
172
- Contributions are welcome! Please follow these steps:
173
-
174
- 1. Fork the repository
175
- 2. Create a feature branch: `git checkout -b feature/your-feature`
176
- 3. Commit changes: `git commit -m "feat: your feature description"`
177
- 4. Push to branch: `git push origin feature/your-feature`
178
- 5. Create a Pull Request
179
-
180
- ## License
181
-
182
- [MIT](LICENSE)
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://img.shields.io/github/license/MengXi-Studio/vite-plugin.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@meng-xi/vite-plugin?color=blue)](https://www.npmjs.com/package/@meng-xi/vite-plugin)
12
+ ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
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)