Skip to content

Commit

Permalink
chore: simplify filter plugin code (#10459)
Browse files Browse the repository at this point in the history
  • Loading branch information
yucccc committed Oct 14, 2022
1 parent 0cfd26c commit 5d9b810
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions packages/vite/src/node/config.ts
Expand Up @@ -414,12 +414,7 @@ export async function resolveConfig(
mode = inlineConfig.mode || config.mode || mode
configEnv.mode = mode

// Some plugins that aren't intended to work in the bundling of workers (doing post-processing at build time for example).
// And Plugins may also have cached that could be corrupted by being used in these extra rollup calls.
// So we need to separate the worker plugin from the plugin that vite needs to run.
const rawWorkerUserPlugins = (
(await asyncFlatten(config.worker?.plugins || [])) as Plugin[]
).filter((p) => {
const filterPlugin = (p: Plugin) => {
if (!p) {
return false
} else if (!p.apply) {
Expand All @@ -429,22 +424,19 @@ export async function resolveConfig(
} else {
return p.apply === command
}
})
}
// Some plugins that aren't intended to work in the bundling of workers (doing post-processing at build time for example).
// And Plugins may also have cached that could be corrupted by being used in these extra rollup calls.
// So we need to separate the worker plugin from the plugin that vite needs to run.
const rawWorkerUserPlugins = (
(await asyncFlatten(config.worker?.plugins || [])) as Plugin[]
).filter(filterPlugin)

// resolve plugins
const rawUserPlugins = (
(await asyncFlatten(config.plugins || [])) as Plugin[]
).filter((p) => {
if (!p) {
return false
} else if (!p.apply) {
return true
} else if (typeof p.apply === 'function') {
return p.apply({ ...config, mode }, configEnv)
} else {
return p.apply === command
}
})
).filter(filterPlugin)

const [prePlugins, normalPlugins, postPlugins] =
sortUserPlugins(rawUserPlugins)

Expand Down

0 comments on commit 5d9b810

Please sign in to comment.