The BuildEntryFunction type defines a custom build entry point that lets you hook into the production build process. Use it to run additional work before, after, or in parallel with the default build.
import type { BuildEntryFunction } from "@funstack/static/server";
Create a module that default-exports a BuildEntryFunction, then reference it via the build option in your Vite config:
// vite.config.ts
import funstackStatic from "@funstack/static";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
funstackStatic({
entries: "./src/entries.tsx",
build: "./src/build.ts",
}),
],
});
// src/build.ts
import type { BuildEntryFunction } from "@funstack/static/server";
export default (async ({ build, outDir }) => {
// Run the default build
await build();
// ... do additional work after the build
}) satisfies BuildEntryFunction;
type BuildEntryFunction = (context: BuildEntryContext) => Promise<void> | void;
interface BuildEntryContext {
build: () => Promise<void>;
outDir: string;
}
Type: () => Promise<void>
Performs the default build flow (rendering entries and writing output files). You must call this function to produce the standard build output. You can run additional work before, after, or in parallel with it.
Type: string
Absolute path to the output directory where built files are written. Use this to write additional files alongside the build output.
import { writeFile } from "node:fs/promises";
import path from "node:path";
import type { BuildEntryFunction } from "@funstack/static/server";
export default (async ({ build, outDir }) => {
const sitemap = generateSitemap(); // your sitemap logic
await Promise.all([
build(),
writeFile(path.join(outDir, "sitemap.xml"), sitemap),
]);
}) satisfies BuildEntryFunction;
By running build() and writeFile() in parallel with Promise.all, the sitemap is generated without adding to the total build time.
import type { BuildEntryFunction } from "@funstack/static/server";
export default (async ({ build }) => {
console.log("Build starting...");
await build();
console.log("Build complete!");
}) satisfies BuildEntryFunction;
build option is only used during production builds (vite build), not in dev mode.build option is specified, the default build flow runs automatically.build option)