Next.js static export
With output: "export", next build writes plain HTML to out. Run Headlark on that folder before it's deployed.
1. Turn on static export
// next.config.mjs
export default {
output: "export",
};
2. Install and add it to your build script
npm i -D headlark
// package.json
"scripts": {
"build": "next build && headlark out --site-url https://example.com"
}
out/about.html becomes https://example.com/about; with trailingSlash: true, out/about/index.html becomes https://example.com/about/. With a basePath, add it to the address: --site-url https://example.com/docs/. The 404 page is left alone.
3. Add your key
Set HEADLARK_KEY to your site's secret key from the dashboard in the build environment.
HEADLARK_KEY=sk_... npm run build
Good to know
- Pages rendered on request (a Next.js server, not an export) have no HTML at build time, so the build step can't reach them. Use the deploy hook with the snippet for those.
- Headlark rewrites titles and descriptions and keeps the canonical, robots and structured data your
metadataalready sets. - Rebuilds are free when a page's content hasn't changed. See pricing for page and rewrite limits.