blitz export
allows you to export your app to static HTML,
which can be run standalone without the need of a Node.js server.
The exported app supports only some features of Blitz, like dynamic routes, prefetching, preloading and dynamic imports. It does not support queries / mutations, authentication or database access.
blitz export
works by prerendering all pages to HTML. For dynamic
routes, your page can export a getStaticPaths
function to let the exporter know which HTML pages to generate for that
route.
blitz export
is intended for scenarios where none of your pages have
server-side or incremental data requirements (though statically-rendered
pages can still fetch data on the client side normally).
If you're looking to make a hybrid site where only some pages are
prerendered to static HTML, Blitz already does that automatically for you!
If your page doesn't use getServerSideProps
, then it will be a static
HTML page.
blitz export
also causes features like
Incremental Static Generation and Regeneration
to be disabled, as they require blitz start
or a serverless deployment
to function.
Develop your app as you normally do with Blitz. Then run:
blitz build
blitz export
For that you may want to update the scripts in your package.json
like
this:
"scripts": {
"build": "blitz build && blitz export"
}
And run it with:
yarn build
Then you'll have a static version of your app in the out directory.
By default, blitz export
doesn't require any configuration. It will
output a static HTML file for each page in your pages directory (or more
for dynamic routes, where it will call
getStaticPaths
and generate pages based on the result). For more
advanced scenarios, you can define a parameter called
exportPathMap
in your blitz.config.js
file to configure exactly which pages will be generated.
By default, blitz export
will generate an out directory, which can be
served by any static hosting service or CDN.
getServerSideProps
cannot be used within pages because the method
requires a server. Consider using getStaticProps
instead.fallback: true
mode of getStaticPaths
is not supported when
using blitz export
.blitz export
. However, other loader options will work.