From 6567ac375da156354ec2e7c1aea60c3ae765edac Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 18 Oct 2022 17:09:11 +0800 Subject: [PATCH] feat(kit): support plugin array for `addVitePlugin` and `addWebpackPlugin` (#8270) --- packages/kit/src/build.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/build.ts b/packages/kit/src/build.ts index b28384397c..b602b8a45d 100644 --- a/packages/kit/src/build.ts +++ b/packages/kit/src/build.ts @@ -117,19 +117,27 @@ export function extendViteConfig ( /** * Append Webpack plugin to the config. */ -export function addWebpackPlugin (plugin: WebpackPluginInstance, options?: ExtendWebpackConfigOptions) { +export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions) { extendWebpackConfig((config) => { config.plugins = config.plugins || [] - config.plugins.push(plugin) + if (Array.isArray(plugin)) { + config.plugins.push(...plugin) + } else { + config.plugins.push(plugin) + } }, options) } /** * Append Vite plugin to the config. */ -export function addVitePlugin (plugin: VitePlugin, options?: ExtendViteConfigOptions) { +export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) { extendViteConfig((config) => { config.plugins = config.plugins || [] - config.plugins.push(plugin) + if (Array.isArray(plugin)) { + config.plugins.push(...plugin) + } else { + config.plugins.push(plugin) + } }, options) }