The easiest way to deploy Next.js to production is to use the Vercel platform from the creators of Next.js. Vercel is an all-in-one platform with Global CDN supporting static & JAMstack deployment and Serverless Functions.
If you haven’t already done so, push your Next.js app to a Git provider of your choice: GitHub, GitLab, or BitBucket. Your repository can be private or public.
Then, follow these steps:
Congratulations! You’ve just deployed your Next.js app! If you have questions, take a look at the Vercel documentation.
If you’re using a custom server, we strongly recommend migrating away from it (for example, by using dynamic routing). If you cannot migrate, consider other hosting options.
Let’s talk about the workflow we recommend using. Vercel supports what we call the DPS workflow: Develop, Preview, and Ship:
master
). Vercel will automatically create a production deployment.By using the DPS workflow, in addition to doing code reviews, you can do deployment previews. Each deployment creates a unique URL that can be shared or used for integration tests.
Vercel is made by the creators of Next.js and has first-class support for Next.js.
For example, the hybrid pages approach is fully supported out of the box.
Next.js can be deployed to any hosting provider that supports Node.js. This is the approach you should take if you’re using a custom server.
Make sure your package.json
has the "build"
and "start"
scripts:
{
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
}
next build
builds the production application in the .next
folder. After building, next start
starts a Node.js server that supports hybrid pages, serving both statically generated and server-side rendered pages.
If you’d like to do a static HTML export of your Next.js app, follow the directions on our documentation. By default, next export
will generate an out
directory, which can be served by any static hosting service or CDN.
We strongly recommend using Vercel even if your Next.js app is fully static. Vercel is optimized to make static Next.js apps blazingly fast.
next export
works with Zero Config deployments on Vercel.