gio export
Render every page of a GioJS app to static HTML in out/, with the client chunks that hydrate it, for any static host.
npx gio exportpnpm exec gio exportyarn gio exportbunx gio exportReference
gio export takes no options besides -h / --help. It is configured through the environment:
| Option | Type | Default | Description |
|---|---|---|---|
GIO_APP_DIR | path | ./app | The app directory. The project root (public/, .env files) is its parent. |
GIO_OUT_DIR | path | ./out | Where the site is written. |
NODE_ENV | string | production | development exports with React's development build and the .env.development* files; anything else (or unset) is production. Use production for anything you publish: the development build writes error details into the HTML. |
GIO_SITE_URL | URL | - | The site's origin (https://example.com). Makes the generated sitemap.xml possible and adds its URL to the generated robots.txt. Relative URLs that app/sitemap.ts or app/robots.ts return are resolved against it. |
GIO_ENV_FILES | 0 | 1 | - | 0 or false loads no .env files; 1 or true loads them even when [env] files = false. |
Behavior
- Loads the project's
.envfiles with the server's precedence (variables already set win).GIO_PUBLIC_*values are frozen into the output. - Renders each page through the same pipeline the server uses, running
getServerSidePropsat export time. A dynamic route is exported once per entry of itsgetStaticPaths(); without one it is skipped. - Writes
out/<path>/index.htmlper page,out/404.html(fromapp/not-found, or the built-in page), the client chunks underout/_next/static/chunks/and the stylesheets underout/_next/static/css/. Each page carries its props as JSON and hydrates, soGioLinknavigation works on a static host. - Copies
public/to the root ofout/and toout/public/, as the server serves it. A rendered page wins over apublic/file with the same output path. - Writes
app/sitemap.*,app/robots.*andapp/manifest.*assitemap.xml,robots.txtandmanifest.webmanifest, unlesspublic/has the same file. Without them it generates arobots.txtthat allows everything, and asitemap.xmlof every exported page whenGIO_SITE_URLis set. - Never starts the Rust server, so it works without the platform binary. Route handlers, WebSockets, middleware rules, image optimization and the page cache need the server and are not part of the export.
The summary lists what was written, what ships without client JS, and what was skipped:
text
[giojs] loaded env: .env.production
[giojs] static export: /home/me/site/app → /home/me/site/out
[giojs] rendered 6 page(s):
✓ / (index)
✓ /about
✓ /blog
✓ /posts/1
✓ /posts/2
✓ /posts/3
[giojs] skipped 1:
- /drafts/:id - dynamic route without getStaticPaths()
[giojs] ✔ static export complete → /home/me/site/out
[giojs] deploy the out/ folder to any static host (Cloudflare Pages, GitHub Pages, …)Reasons a page is skipped:
| Reason | Why |
|---|---|
dynamic route without getStaticPaths() | The export cannot know which params to render. |
render error: ... (ref ..., details in the error log) | The page threw; the reference matches the logged line with the real message and stack. |
redirect (307) - server only | A redirect needs a server to answer it. |
notFound() - nothing written | The page called notFound(). |
streaming/SSE route - server only | An event stream cannot be a file. |
Examples
Export with a sitemap
bash
GIO_SITE_URL=https://example.com npx gio exportExport to another directory
bash
GIO_OUT_DIR=dist npx gio exportA static site's build script
package.json
{
"scripts": {
"build": "tsc --noEmit && gio export"
}
}npm create giojs@latest -- --static writes this script; a type error stops the build before the export.
Good to know
- The exit code is
0even when pages were skipped: read the summary, or check that the files you expect exist in CI. It is1when@gio.js/coreortsxis missing, a.envfile cannot be parsed, or the export crashes (a route conflict, for example). out/is not emptied first: files from an earlier export that this one does not write stay there. Delete it in your build script if pages can disappear.- Never return secrets from
getServerSidePropsof an exported page: the props are in the HTML. <GioImage>renders a plainsrcin an export (there is no optimizer on a static host).
Related
- Static Export - the guide
gio build standalonewhen you need the server- Environment Variables
Version history
| Version | Changes |
|---|---|
v0.1.0-beta.8 | Pages hydrate (client chunks and props are exported), stylesheets and CSS Modules ship, public/ is copied to the root, .env files load, NODE_ENV defaults to production, app/sitemap / robots / manifest are written, and failed routes are listed with their error reference. |
v0.1.0-beta.3 | Generates robots.txt and, with GIO_SITE_URL, sitemap.xml. |
v0.1.0-beta.2 | Introduced. |