Static HTML 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 almost every feature of Next.js, including dynamic routes, prefetching, preloading and dynamic imports.
next export
works by prerendering all pages to HTML. For dynamic routes, your page can export a function to let the exporter know which HTML pages to generate for that route.
Develop your app as you normally do with Next.js. Then run:
For that you may want to update the scripts in your package.json
like this:
And run it with:
Then you’ll have a static version of your app in the out
directory.
By default next 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 and generate pages based on the result). For more advanced scenarios, you can define a parameter called exportPathMap
in your file to configure exactly which pages will be generated.
We strongly recommend using Vercel even if your Next.js app is fully static. is optimized to make static Next.js apps blazingly fast.
next export
works with Zero Config deployments on Vercel.
With
next export
, we build an HTML version of your app. At export time, we callgetStaticProps
for each page that exports it, and pass the result to the page’s component. It’s also possible to use the older API instead ofgetStaticProps
, but it comes with a few caveats:getInitialProps
cannot be used alongsidegetStaticProps
orgetStaticPaths
on any given page. If you have dynamic routes, instead of usinggetStaticPaths
you’ll need to configure theexportPathMap
parameter in your file to let the exporter know which HTML files it should output.- When is called during export, the
req
andres
fields of itscontext
parameter will be empty objects, since during export there is no server running. getInitialProps
should fetch from an API and cannot use Node.js-specific libraries or the file system likegetStaticProps
can.
It’s recommended to use and migrate towards
getStaticProps
overgetInitialProps
whenever possible.The mode of
getStaticPaths
is not supported when usingnext export
.API Routes are not supported by this method because they can’t be prerendered to HTML.