How to deploy a next.js project in netlify?

How to deploy a next.js project in netlify?

Installing the Netlify Nextjs plugin

Netlify Nextjs plugin enables Next's dynamic features including dynamic routes, API routes, and Preview Mode, etc on the netlify functions platform.

The plugin installs automatically for new Next.js sites on Netlify. You can also install it manually like this:

yarn add @netlify/plugin-nextjs -D

...then add the plugin to your netlify.toml file:

package = "@netlify/plugin-nextjs"

The final netlify.toml file would look like, below

  # nextjs build command
  command = "next build"

  # nextjs output directory   
  publish = ".next" 

  # default ignore command
  ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ."  

# netlify nextjs plugin that helps nextjs ISR and SSR and API routes, etc
package = "@netlify/plugin-nextjs"

Deploy the nextjs project

-> Create a new Netlify site using the netlify dashbaord. UI. First, visit in your browser.

-> Choose your preferred Git provider from the options and authorize Netlify to access the repository you want to deploy.

-> In the next screen, select your Next.js repo from the list. -> We can see that, it automatically picked up the build command and publish directory. -> Choose the owner and branch to deploy image.png -> Click "Deploy Site"

Happy Netlifying!!