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.

Built-in Plugins

Four ready-to-use plugins covering common build scenarios:

PluginDescription
copyFileCopy files or directories to specified locations after build
generateRouterAuto-generate router configuration from uni-app's pages.json
generateVersionAuto-generate version numbers with file output and global variable injection
injectIcoInject website icon links into HTML files

Plugin Development Framework

Export core components to quickly build custom plugins:

ComponentDescription
BasePluginPlugin base class providing lifecycle management, logging, validation and standard features
createPluginFactoryPlugin factory function that handles options merging and instantiation
LoggerSingleton logger manager with plugin-level log control
ValidatorChainable configuration validator ensuring parameter type correctness

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'
}

Utility Functions

Exported utility functions:

  • File System: readFileSync, writeFileContent, copySourceToTarget, readDirRecursive, etc.
  • Formatting: formatDate, parseTemplate, generateRandomHash, padNumber, etc.
  • Object Utils: deepMerge, toCamelCase, toPascalCase, stripJsonComments, etc.

Next Steps

Released under the MIT License.