Skip to content
Permalink
Browse files
refactor: config hook helper function (#9982)
  • Loading branch information
musicq committed Sep 5, 2022
1 parent 855f2f0 commit 9c1be108bfb1eac3dbbe432214349153d8b9ed5e
Showing 1 changed file with 23 additions and 20 deletions.
@@ -442,16 +442,7 @@ export async function resolveConfig(

// run config hooks
const userPlugins = [...prePlugins, ...normalPlugins, ...postPlugins]
for (const p of getSortedPluginsByHook('config', userPlugins)) {
const hook = p.config
const handler = hook && 'handler' in hook ? hook.handler : hook
if (handler) {
const res = await handler(config, configEnv)
if (res) {
config = mergeConfig(config, res)
}
}
}
config = await runConfigHook(config, userPlugins, configEnv)

if (process.env.VITE_TEST_WITHOUT_PLUGIN_COMMONJS) {
config = mergeConfig(config, {
@@ -611,16 +602,7 @@ export async function resolveConfig(
...workerNormalPlugins,
...workerPostPlugins
]
for (const p of getSortedPluginsByHook('config', workerUserPlugins)) {
const hook = p.config
const handler = hook && 'handler' in hook ? hook.handler : hook
if (handler) {
const res = await handler(workerConfig, configEnv)
if (res) {
workerConfig = mergeConfig(workerConfig, res)
}
}
}
workerConfig = await runConfigHook(workerConfig, workerUserPlugins, configEnv)
const resolvedWorkerOptions: ResolveWorkerOptions = {
format: workerConfig.worker?.format || 'iife',
plugins: [],
@@ -1089,6 +1071,27 @@ async function loadConfigFromBundledFile(
}
}

async function runConfigHook(
config: InlineConfig,
plugins: Plugin[],
configEnv: ConfigEnv
): Promise<InlineConfig> {
let conf = config

for (const p of getSortedPluginsByHook('config', plugins)) {
const hook = p.config
const handler = hook && 'handler' in hook ? hook.handler : hook
if (handler) {
const res = await handler(conf, configEnv)
if (res) {
conf = mergeConfig(conf, res)
}
}
}

return conf
}

export function getDepOptimizationConfig(
config: ResolvedConfig,
ssr: boolean

0 comments on commit 9c1be10

Please sign in to comment.