Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide build end hook #709

Merged
merged 2 commits into from Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/node/build/build.ts
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
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