Skip to content

Commit 5d9b810

Browse files
authoredOct 14, 2022
chore: simplify filter plugin code (#10459)
1 parent 0cfd26c commit 5d9b810

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed
 

‎packages/vite/src/node/config.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,7 @@ export async function resolveConfig(
414414
mode = inlineConfig.mode || config.mode || mode
415415
configEnv.mode = mode
416416

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

434435
// resolve plugins
435436
const rawUserPlugins = (
436437
(await asyncFlatten(config.plugins || [])) as Plugin[]
437-
).filter((p) => {
438-
if (!p) {
439-
return false
440-
} else if (!p.apply) {
441-
return true
442-
} else if (typeof p.apply === 'function') {
443-
return p.apply({ ...config, mode }, configEnv)
444-
} else {
445-
return p.apply === command
446-
}
447-
})
438+
).filter(filterPlugin)
439+
448440
const [prePlugins, normalPlugins, postPlugins] =
449441
sortUserPlugins(rawUserPlugins)
450442

0 commit comments

Comments
 (0)
Please sign in to comment.