Deploy a Next.js application on Netlify
Learn how to prepare and deploy a Next.js application on Netlify.
In the last document, we learned how to create a simple Next.js application. In this document, you will learn how to deploy a Next.js application on Netlify.
Configuring the project for deployment and build
Before deploying the application, we must ensure that the Next.js application is ready for production. Let's start with optimizing the images for production. First, install the following packages:
The next-compose-plugins
provides a simple API and modules to make Next.js plugin configurations easier. The next-optimized-images
package will automatically optimize images used in this project.
In the next.config.js
file, make sure to have the following configurations.
After the configuration of the Next.js plugins, let's write the netlify.toml
configuration file.
In the code above, we specify the required commands and configuration for Netlify to build the project and where to publish the built project. To ensure the build will pass on Netlify, you can run the build command.
if there is no error, the project is ready for deployment on Netlify.
Deploying on Netlify
We assume here that you have a Netlify account and that the project source code is hosted on a service like Github, Gitlab, etc.
First, add a new site. If your project is already available on an online code hosting service, choose the import an existing project.
Conclusion
In this documentation, we quickly learned how to deploy a Next.js
application on Netlify. In the next document, we will discuss best practices to follow when working with Next.js
.
Last updated
Was this helpful?