Skip to content

Commit

Permalink
feat(plugin-api): support async configResolved hooks (fixes vitejs#2949)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikg committed Apr 11, 2021
1 parent 92b3193 commit 06e008e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo

### `configResolved`

- **Type:** `(config: ResolvedConfig) => void`
- **Kind:** `sync`, `sequential`
- **Type:** `(config: ResolvedConfig) => void | Promise<void>`
- **Kind:** `async`, `sequential`

Called after the Vite config is resolved. Use this hook to read and store the final resolved config. It is also useful when the plugin needs to do something different based the command is being run.

Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ export async function resolveConfig(
)

// call configResolved hooks
userPlugins.forEach((p) => {
for (const p of userPlugins) {
if (p.configResolved) {
p.configResolved(resolved)
await p.configResolved(resolved)
}
})
}

if (process.env.DEBUG) {
debug(`using resolved config: %O`, {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface Plugin extends RollupPlugin {
/**
* Use this hook to read and store the final resolved vite config.
*/
configResolved?: (config: ResolvedConfig) => void
configResolved?: (config: ResolvedConfig) => void | Promise<void>
/**
* Configure the vite server. The hook receives the {@link ViteDevServer}
* instance. This can also be used to store a reference to the server
Expand Down

0 comments on commit 06e008e

Please sign in to comment.