Gatsby Postbuild
Project Overview
Gatsby plugin that adds an event-based pipeline that runs after gatsby build
to transform and optimize the files in /public
. It ships ready-made tasks (PurgeCSS, HTTP headers, Minify) and lets you define custom tasks that hook into file-type events (e.g., HTML AST) or generic file events.
Key Features
- Provider headers generation: emits hosting configs (e.g., Firebase
firebase.json
, Netlify_headers
, Vercel) for resource hints (prefetch
,preload
,preconnect
), caching, security and other critical headers. - Built-in tasks: PurgeCSS, HTTP headers (provider presets), Minify (terser/cssnano).
- Custom tasks via events: register handlers for generic
contents
or HTML events likeparse
,tree
,node
,serialize
,write
. - Processing controls: choose parallel or sequential strategies and set concurrency globally or per extension.
- Ignore & per-task filters: exclude files globally or per task (e.g., skip specific HTML paths for PurgeCSS).
- Reporting: optional
postbuild.log.json
and console summary with toggles. - Lifecycle hooks:
on.postbuild
,on.shutdown
, and[extension].configure
for setup/teardown and per-type config.
Why it exists
- Close the “last mile”. Gatsby stops at generating
/public
; teams hack the rest in CI scripts. Postbuild provides a structured, repeatable stage for that work. - Put critical headers at the edge. Generate provider configs so browsers/crawlers receive resource hints in the first response, enabling action before the page HTML is parsed.
- Make builds reproducible. Run the same tasks locally and in CI, with clear logs and one config.
- Unify common optimizations. PurgeCSS, minification, HTTP headers, redirects, and custom file transforms—all in one pipeline.
Check out the project repository on Github for more info.