Skip to content

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:

GroupDescriptionPlugins
compressCompressioncompressAssets, imageOptimizer
generateGenerationautoImport, generateUni, generatePages, generateRouter, generateVersion
injectInjectionhtmlInject, loadingManager, faviconManager, versionUpdateChecker
analyzeAnalysisbundleAnalyzer, buildProgress
copyCopycopyFile, assetManifest
guardGuardenvGuard
proxyProxyproxyManager

Plugin Development Framework

Export core components to quickly build custom plugins:

ComponentDescription
BasePluginPlugin base class providing lifecycle management, logging, validation, and safe execution wrappers
createPluginFactoryPlugin factory function that handles options merging, normalization, and instantiation
LoggerSingleton logger manager with plugin-level log control
ValidatorChainable 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

  1. Installation — Install dependencies
  2. Quick Start — Get started in 5 minutes
  3. Core Concepts — Understand the plugin system and lifecycle
  4. On-demand Import — Optimize bundle size
  5. Best Practices — Scenario-based recommendations and common pitfalls

Next Steps

Released under the MIT License.