FFUNSTACK Static
DocsAPILearn

Getting Started

IntroductionMigrating from Vite SPA

Learn

React Server ComponentsHow It WorksOptimizing RSC PayloadsUsing lazy() in ServerPrefetching with ActivityFile-System Routing

Advanced

Multiple Entrypoints (SSG)Server-Side Rendering

API Reference

funstackStatic()defer()BuildEntryFunctionEntryDefinition

Help

FAQ

BuildEntryFunction

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

import type { BuildEntryFunction } from "@funstack/static/server";

Usage

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 Definition

type BuildEntryFunction = (context: BuildEntryContext) => Promise<void> | void;

interface BuildEntryContext {
  build: () => Promise<void>;
  outDir: string;
}

Context Properties

build

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.

outDir

Type: string

Absolute path to the output directory where built files are written. Use this to write additional files alongside the build output.

Examples

Generate a sitemap alongside the build

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.

Run work before or after the build

import type { BuildEntryFunction } from "@funstack/static/server";

export default (async ({ build }) => {
  console.log("Build starting...");
  await build();
  console.log("Build complete!");
}) satisfies BuildEntryFunction;

Notes

  • The build entry module runs in the RSC environment, so you have access to Node.js APIs.
  • The build option is only used during production builds (vite build), not in dev mode.
  • If no build option is specified, the default build flow runs automatically.

See Also

  • funstackStatic() - Plugin configuration (includes the build option)
  • Multiple Entrypoints - Multi-page static site generation