Skip to content

Commit

Permalink
feat(plugin): plugin config hook supports return promise (#2800)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuweiGL committed Apr 9, 2021
1 parent ffcb7ce commit 5dfd0e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ export async function resolveConfig(

// run config hooks
const userPlugins = [...prePlugins, ...normalPlugins, ...postPlugins]
userPlugins.forEach((p) => {
for (const p of userPlugins) {
if (p.config) {
const res = p.config(config, configEnv)
const res = await p.config(config, configEnv)
if (res) {
config = mergeConfig(config, res)
}
}
})
}

// resolve root
const resolvedRoot = normalizePath(
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export interface Plugin extends RollupPlugin {
* Note: User plugins are resolved before running this hook so injecting other
* plugins inside the `config` hook will have no effect.
*/
config?: (config: UserConfig, env: ConfigEnv) => UserConfig | null | void
config?: (
config: UserConfig,
env: ConfigEnv
) => UserConfig | null | void | Promise<UserConfig | null | void>
/**
* Use this hook to read and store the final resolved vite config.
*/
Expand Down

0 comments on commit 5dfd0e8

Please sign in to comment.