Import
Basic Usage
Generate Static Files
ThetoSSG function pre-renders your app routes:
File System Module
Provide a file system module for writing files:Node.js
Deno
Bun
Options
Output Directory
string
default:"./static"
Output directory for generated files
Concurrency
Control how many routes are processed in parallel:number
default:"2"
Number of routes to process concurrently
Extension Mapping
Customize file extensions based on content type:Dynamic Routes
For routes with parameters, usessgParams middleware to define which parameter values to generate:
Basic Dynamic Routes
Dynamic Parameters from Function
Multiple Parameters
Controlling SSG Behavior
Disable SSG for Specific Routes
Prevent certain routes from being statically generated:Only Generate During SSG
Make routes available only during static generation:Check if in SSG Context
Hooks
Customize the generation process with hooks:Before Request Hook
Modify requests before processing:false to skip a route:
After Response Hook
Modify responses before writing files:false to skip writing the file:
After Generate Hook
Run logic after all files are generated:Plugins
Plugins bundle hooks together:Built-in Plugins
function
Default plugin with standard behavior
function
Handles redirect responses during generation
Result Object
ThetoSSG function returns a result object:
Success Case
Error Case
Build Script Example
Create a build script for your project:package.json:
Deployment
Deploy generated files to static hosting:Vercel
Deploy the
dist folder as a static siteNetlify
Configure build command and publish directory
Cloudflare Pages
Push to Git and configure Pages project
GitHub Pages
Deploy from repository with GitHub Actions
Best Practices
Use
ssgParams for all dynamic routes, otherwise they will be skipped during generation.Use
isSSGContext to provide different behavior during static generation vs. runtime.