Running a Next.js production build
Next.js supports two kinds of production usage, static and dynamic, the main difference being that a static build can be served by any static HTTP server as a static website, whereas dynamic usage means that there will be a Next.js server that executes the production build:
- Static mode is best suited for simple websites with no dynamic content. We need to add a script to
package.json
:
{ "scripts": { "build": "next build", "static": "next export" } }
- Then, we have to add a
next.config.js
with a path map (this was fixed in6.0.0
; you no longer have to do it for 1-1 matches of filesystems and URLs):
// next.config.js module.exports = { exportPathMap: () => ({ '/': {page: '/'} }) };
- Now, we run this:
$ npm run build $ npm run static
This will create a static build that we can deploy somewhere. We will cover this in later chapters.
- In order to build and run the...