Skip to content

Commit

Permalink
feat: provide build end hook (#709)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <[email protected]>
  • Loading branch information
userquin and brc-dd authored Jul 9, 2022
1 parent 22006e8 commit e0b730a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/node/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ export async function build(
await fs.remove(siteConfig.tempDir)
}

await siteConfig.buildEnd?.(siteConfig)

console.log(`build complete in ${((Date.now() - start) / 1000).toFixed(2)}s.`)
}
10 changes: 9 additions & 1 deletion src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export interface UserConfig<ThemeConfig = any> {
* @default false
*/
ignoreDeadLinks?: boolean

/**
* Build end hook: called when SSG finish.
* @param siteConfig The resolved configuration.
*/
buildEnd?: (siteConfig: SiteConfig) => Promise<void>
}

export type RawConfigExports<ThemeConfig = any> =
Expand All @@ -88,6 +94,7 @@ export interface SiteConfig<ThemeConfig = any>
| 'mpa'
| 'lastUpdated'
| 'ignoreDeadLinks'
| 'buildEnd'
> {
root: string
srcDir: string
Expand Down Expand Up @@ -166,7 +173,8 @@ export async function resolveConfig(
vite: userConfig.vite,
shouldPreload: userConfig.shouldPreload,
mpa: !!userConfig.mpa,
ignoreDeadLinks: userConfig.ignoreDeadLinks
ignoreDeadLinks: userConfig.ignoreDeadLinks,
buildEnd: userConfig.buildEnd
}

return config
Expand Down

0 comments on commit e0b730a

Please sign in to comment.