feat(kit): support plugin array for addVitePlugin and addWebpackPlugin (#8270)

This commit is contained in:
Anthony Fu 2022-10-18 17:09:11 +08:00 committed by GitHub
parent b1c842e8be
commit 6567ac375d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,19 +117,27 @@ export function extendViteConfig (
/** /**
* Append Webpack plugin to the config. * Append Webpack plugin to the config.
*/ */
export function addWebpackPlugin (plugin: WebpackPluginInstance, options?: ExtendWebpackConfigOptions) { export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions) {
extendWebpackConfig((config) => { extendWebpackConfig((config) => {
config.plugins = config.plugins || [] config.plugins = config.plugins || []
config.plugins.push(plugin) if (Array.isArray(plugin)) {
config.plugins.push(...plugin)
} else {
config.plugins.push(plugin)
}
}, options) }, options)
} }
/** /**
* Append Vite plugin to the config. * Append Vite plugin to the config.
*/ */
export function addVitePlugin (plugin: VitePlugin, options?: ExtendViteConfigOptions) { export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) {
extendViteConfig((config) => { extendViteConfig((config) => {
config.plugins = config.plugins || [] config.plugins = config.plugins || []
config.plugins.push(plugin) if (Array.isArray(plugin)) {
config.plugins.push(...plugin)
} else {
config.plugins.push(plugin)
}
}, options) }, options)
} }