From 6d7f4eed2ed96266f56c865c804676dcc5e3b30d Mon Sep 17 00:00:00 2001 From: codehz Date: Fri, 20 Dec 2024 11:00:36 +0800 Subject: [PATCH] expose onLoadPageFile --- build.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/build.ts b/build.ts index d905f6f..8faca99 100644 --- a/build.ts +++ b/build.ts @@ -14,6 +14,16 @@ export async function build({ minify = Bun.env.NODE_ENV === "production", define, plugins, + onLoadPageFile = async ({ path, loader }) => { + const contents = await Bun.file(path).text(); + return { + contents: contents.replaceAll( + /\/\/\s*@server-side[^\n\S]*\n[^\n]+\n/g, + "" + ), + loader, + }; + }, }: { baseDir: string; buildDir?: string; @@ -23,6 +33,7 @@ export async function build({ minify?: boolean; define?: Record; plugins?: import("bun").BunPlugin[]; + onLoadPageFile?: import("bun").OnLoadCallback; }) { const entrypoints = [join(baseDir, hydrate)]; const absPageDir = join(baseDir, pageDir); @@ -81,16 +92,7 @@ export async function build({ ); build.onLoad( { namespace: "client", filter: /\.ts[x]$/ }, - async ({ path, loader }) => { - const contents = await Bun.file(path).text(); - return { - contents: contents.replaceAll( - /\/\/\s*@server-side[^\n\S]*\n[^\n]+\n/g, - "" - ), - loader, - }; - } + onLoadPageFile ); }, },