@@ -442,16 +442,7 @@ export async function resolveConfig(
442
442
443
443
// run config hooks
444
444
const userPlugins = [ ...prePlugins , ...normalPlugins , ...postPlugins ]
445
- for ( const p of getSortedPluginsByHook ( 'config' , userPlugins ) ) {
446
- const hook = p . config
447
- const handler = hook && 'handler' in hook ? hook . handler : hook
448
- if ( handler ) {
449
- const res = await handler ( config , configEnv )
450
- if ( res ) {
451
- config = mergeConfig ( config , res )
452
- }
453
- }
454
- }
445
+ config = await runConfigHook ( config , userPlugins , configEnv )
455
446
456
447
if ( process . env . VITE_TEST_WITHOUT_PLUGIN_COMMONJS ) {
457
448
config = mergeConfig ( config , {
@@ -611,16 +602,7 @@ export async function resolveConfig(
611
602
...workerNormalPlugins ,
612
603
...workerPostPlugins
613
604
]
614
- for ( const p of getSortedPluginsByHook ( 'config' , workerUserPlugins ) ) {
615
- const hook = p . config
616
- const handler = hook && 'handler' in hook ? hook . handler : hook
617
- if ( handler ) {
618
- const res = await handler ( workerConfig , configEnv )
619
- if ( res ) {
620
- workerConfig = mergeConfig ( workerConfig , res )
621
- }
622
- }
623
- }
605
+ workerConfig = await runConfigHook ( workerConfig , workerUserPlugins , configEnv )
624
606
const resolvedWorkerOptions : ResolveWorkerOptions = {
625
607
format : workerConfig . worker ?. format || 'iife' ,
626
608
plugins : [ ] ,
@@ -1089,6 +1071,27 @@ async function loadConfigFromBundledFile(
1089
1071
}
1090
1072
}
1091
1073
1074
+ async function runConfigHook (
1075
+ config : InlineConfig ,
1076
+ plugins : Plugin [ ] ,
1077
+ configEnv : ConfigEnv
1078
+ ) : Promise < InlineConfig > {
1079
+ let conf = config
1080
+
1081
+ for ( const p of getSortedPluginsByHook ( 'config' , plugins ) ) {
1082
+ const hook = p . config
1083
+ const handler = hook && 'handler' in hook ? hook . handler : hook
1084
+ if ( handler ) {
1085
+ const res = await handler ( conf , configEnv )
1086
+ if ( res ) {
1087
+ conf = mergeConfig ( conf , res )
1088
+ }
1089
+ }
1090
+ }
1091
+
1092
+ return conf
1093
+ }
1094
+
1092
1095
export function getDepOptimizationConfig (
1093
1096
config : ResolvedConfig ,
1094
1097
ssr : boolean
0 commit comments