next 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.
The way next export works is by prerendering all pages to HTML; it does so based on a mapping called exportPathMap which offers a way to pre-define paths you will render as html.
If your pages don't have
getInitialPropsyou may not neednext exportat all;next buildis already enough thanks to Automatic Static Optimization.
Develop your app as you normally do with Next.js. Then run:
next build && next export
For that you may want to update the scripts in your package.json like this:
"scripts": {
"build": "next build && next export"
}
And run it at once with:
npm run build
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 generate a default exportPathMap with routes for the pages inside the pages directory.
To learn more about
exportPathMapplease visit the documentation for theexportPathMapAPI.
You can read about deploying your Next.js application in the deployment section.
next export, we build an HTML version of your app. At export time we will run the getInitialProps in your pages. The req and res fields of the context object will be empty objects during export as there is no server running.next export. You can learn more about it in the pages section.