From be76a304aacb52ac5e333552d30024be34a8a6a9 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Wed, 24 Mar 2021 02:07:41 -0400 Subject: [PATCH] feat: let `plugins` array contain falsy values (#1649) --- packages/vite/src/node/config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 6ba9279bdad6f4..6c828b94dde93e 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -58,6 +58,8 @@ export function defineConfig(config: UserConfigExport): UserConfigExport { return config } +export type PluginOption = Plugin | false | null | undefined + export interface UserConfig { /** * Project root directory. Can be an absolute path, or a path relative from @@ -90,7 +92,7 @@ export interface UserConfig { /** * Array of vite plugins to use. */ - plugins?: (Plugin | Plugin[])[] + plugins?: (PluginOption | PluginOption[])[] /** * Configure resolver */ @@ -232,8 +234,8 @@ export async function resolveConfig( // resolve plugins const rawUserPlugins = (config.plugins || []).flat().filter((p) => { - return !p.apply || p.apply === command - }) + return p && (!p.apply || p.apply === command) + }) as Plugin[] const [prePlugins, normalPlugins, postPlugins] = sortUserPlugins( rawUserPlugins )