Nextra supports fully static HTML export, allowing you to build your documentation site as a set of pre-rendered HTML, CSS, and JavaScript files with no Node.js server required at runtime. Static exports are ideal for hosting on platforms like GitHub Pages, Nginx, Cloudflare Pages, or any static CDN — you get the full authoring experience of Nextra with the simplicity of static file hosting.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
Getting Started
Add
output: 'export' to your Next.js config and set images to unoptimized mode (required
because Next.js image optimization needs a server):import nextra from 'nextra'
const withNextra = nextra({
// ... Nextra-specific options
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
output: 'export',
images: {
unoptimized: true // required for static export
}
// Optional: change the output directory from 'out' to something else
// distDir: 'dist'
}
export default withNextra(nextConfig)
images: { unoptimized: true } is mandatory for static exports. Without it, Next.js
will throw a build error because the image optimization API requires a running server.Nextra’s Pagefind search integration indexes your built pages. For static exports,
point the Pagefind command at the
.next/server/app directory where Next.js writes
the pre-rendered HTML, and write the index to out/_pagefind:{
"scripts": {
"build": "next build",
"postbuild": "pagefind --site .next/server/app --output-path out/_pagefind"
}
}
The
postbuild script runs automatically after next build completes. It scans the
server-rendered HTML and writes the search index into the static output directory.If you changed the output directory via
distDir in your Next.js config, update the
--output-path argument to match — for example,
pagefind --site .next/server/app --output-path dist/_pagefind.Run the build command for your package manager. The static site will be written to the
out/ directory by default:Deploying the Static Output
Once built, theout/ directory is a self-contained static site. Deploy it to any static hosting platform:
- GitHub Pages
- Nginx
- Cloudflare Pages
Push the contents of
out/ to the gh-pages branch, or configure GitHub Actions to
deploy on every push to main. Set the GitHub Pages source to the gh-pages branch
in your repository settings..github/workflows/deploy.yml
What Works with Static Export
Most of Nextra’s features work fully with static export:✅ Fully supported
✅ Fully supported
- All MDX content with full syntax highlighting (
rehype-pretty-code/ Shiki) - Nextra components:
<Callout>,<Tabs>,<Steps>,<FileTree>, etc. nextra-theme-docsandnextra-theme-blogthemes- Pagefind full-text search (via
postbuildscript) - Dark mode toggle
- Table of contents
- Sidebar navigation generated from
_metafiles - Static images (with
unoptimized: true) - Internationalization (i18n) with static locale pages
- Custom
app/routes alongside MDX pages
❌ Not supported with static export
❌ Not supported with static export
Static export removes all server-side runtime capabilities. The following features require
a running Node.js server and will not work with
output: 'export':- Next.js Image Optimization — use
unoptimized: trueas a workaround - Server Actions — these require a server to execute
- Route Handlers that run at request time (API routes)
- Middleware — runs at the edge, not available in static output
- Incremental Static Regeneration (ISR) — no server to revalidate pages
- Dynamic server-side rendering (
force-dynamicpages)
Configuration Reference
next.config.mjs