feat: add plugin buildStart and buildEnd hooks (#1770)
This commit is contained in:
@@ -46,7 +46,13 @@ export async function dev(
|
||||
if (isBuild) {
|
||||
// Ensure that build dir is empty
|
||||
await fs.emptyDir(outDir);
|
||||
await build(join(dir, "fresh.gen.ts"), options ?? {});
|
||||
|
||||
options = options ?? {};
|
||||
const plugins = options.plugins ?? [];
|
||||
|
||||
await Promise.all(plugins.map((plugin) => plugin.buildStart?.()));
|
||||
await build(join(dir, "fresh.gen.ts"), options);
|
||||
await Promise.all(plugins.map((plugin) => plugin.buildEnd?.()));
|
||||
} else if (options) {
|
||||
const ctx = await ServerContext.fromManifest(manifest, {
|
||||
...options,
|
||||
|
||||
@@ -427,6 +427,15 @@ export interface Plugin<State = Record<string, unknown>> {
|
||||
*/
|
||||
renderAsync?(ctx: PluginAsyncRenderContext): Promise<PluginRenderResult>;
|
||||
|
||||
/**
|
||||
* Called before running the Fresh build task
|
||||
*/
|
||||
buildStart?(): Promise<void> | void;
|
||||
/**
|
||||
* Called after completing the Fresh build task
|
||||
*/
|
||||
buildEnd?(): Promise<void> | void;
|
||||
|
||||
routes?: PluginRoute[];
|
||||
|
||||
middlewares?: PluginMiddleware<State>[];
|
||||
|
||||
Reference in New Issue
Block a user