Skip to content

BasePluginOptions

Base configuration type for all plugins, defining common configuration fields.

typescript
import type { BasePluginOptions } from '@meng-xi/vite-plugin/factory'

Type Definition

typescript
interface BasePluginOptions {
	/** Whether to enable the plugin, default true */
	enabled?: boolean
	/** Error handling strategy, default 'log' */
	errorStrategy?: 'throw' | 'log' | 'ignore'
	/** Plugin log level, default 'info' */
	logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent'
}

Configuration Fields

enabled

Controls whether the plugin is enabled. When set to false, all plugin hooks are skipped.

typescript
// Disable plugin
myPlugin({ enabled: false })

errorStrategy

Controls how plugin internal errors are handled.

ValueDescription
throwLog error and throw exception, aborts build
logLog error only, continues execution (default)
ignoreLog error only, continues execution

WARNING

The throw strategy will abort the entire build process. Only use it when strict build correctness is required.

typescript
// Use throw strategy for critical build plugins
myPlugin({ errorStrategy: 'throw' })

logLevel

Controls plugin log output level. Logs below the set level are ignored.

ValueDescription
debugOutput all level logs
infoOutput info/warn/error logs
warnOutput warn/error logs
errorOutput error logs only
silentNo log output
typescript
// Silent logs in production
myPlugin({ logLevel: process.env.NODE_ENV === 'production' ? 'silent' : 'info' })

Inheritance Example

When creating custom plugin options, extend BasePluginOptions to automatically get common fields.

typescript
import type { BasePluginOptions } from '@meng-xi/vite-plugin/factory'

interface MyPluginOptions extends BasePluginOptions {
	// Custom fields
	outputPath: string
	verbose?: boolean
}

Common and custom fields can be passed together:

typescript
myPlugin({
	// Common fields
	enabled: true,
	errorStrategy: 'log',
	logLevel: 'info',
	// Custom fields
	outputPath: 'dist/output.json',
	verbose: true
})

Released under the MIT License.