Introduction
@meng-xi/vite-plugin is a toolkit that provides practical plugins for Vite, and also serves as a complete Vite Plugin Development Framework.
What It Does
- 17 ready-to-use plugins — Grouped into 7 functional categories (compress / generate / inject / analyze / copy / guard / proxy), covering build optimization, code generation, asset management, and developer experience
- Plugin Development Framework — Exports core components like BasePlugin, Logger, and Validator to quickly build custom Vite plugins
- 14 utility modules — Concurrency control, file system, HTML injection, path processing, and more, all available via sub-path imports
Plugin Groups
Plugins are grouped by functional verb, and can be imported by group or individually:
| Group | Description | Plugins |
|---|---|---|
| compress | Compression | compressAssets, imageOptimizer |
| generate | Generation | autoImport, generateUni, generatePages, generateRouter, generateVersion |
| inject | Injection | htmlInject, loadingManager, faviconManager, versionUpdateChecker |
| analyze | Analysis | bundleAnalyzer, buildProgress |
| copy | Copy | copyFile, assetManifest |
| guard | Guard | envGuard |
| proxy | Proxy | proxyManager |
Plugin Development Framework
Export core components to quickly build custom plugins:
| Component | Description |
|---|---|
| BasePlugin | Plugin base class providing lifecycle management, logging, validation, and safe execution wrappers |
| createPluginFactory | Plugin factory function that handles options merging, normalization, and instantiation |
| Logger | Singleton logger manager with plugin-level log control |
| Validator | Chainable configuration validator supporting required, type, enum, range, and custom validation |
Common Options
All built-in plugins extend BasePlugin and support these common options:
typescript
interface BasePluginOptions {
/** Enable plugin, default true */
enabled?: boolean
/** Show verbose logs, default true */
verbose?: boolean
/** Error handling strategy: throw | log | ignore */
errorStrategy?: 'throw' | 'log' | 'ignore'
}Learning Path
Recommended learning order
- Installation — Install dependencies
- Quick Start — Get started in 5 minutes
- Core Concepts — Understand the plugin system and lifecycle
- On-demand Import — Optimize bundle size
- Best Practices — Scenario-based recommendations and common pitfalls
Next Steps
- Installation — Installation and configuration
- Quick Start — Get started in 5 minutes
- Plugins Overview — Browse all plugins
- Plugin Factory — Develop custom plugins
- GitHub — View source code and examples
