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:

  1. 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"       }     }
  1. Then, we have to add a next.config.js with a path map (this was fixed in 6.0.0; you no longer have to do it for 1-1 matches of filesystems and URLs):
      // next.config.js      module.exports = {          exportPathMap: () => ({              '/': {page: '/'}          })      };
  1. Now, we run this: ...

Get Next.js Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.