Static site
Next.js ↗ is an open-source React framework for creating websites and applications. In this guide, you will create a new Next.js application and deploy it using Cloudflare Pages.
This guide will instruct you how to deploy a static site Next.js project with static exports ↗.
All of the framework guides assume you already have a fundamental understanding of Git ↗. If you are new to Git, refer to this summarized Git handbook ↗ on how to set up Git on your local machine.
If you clone with SSH, you must generate SSH keys ↗ on each computer you use to push or pull from GitHub.
Refer to the GitHub documentation ↗ and Git documentation ↗ for more information.
If you already have a Next.js project that you wish to deploy, ensure that it is configured for static exports ↗, change to its directory, and proceed to the next step. Otherwise, use create-next-app
to create a new Next.js project.
After creating your project, a new my-app
directory will be generated using the official with-static-export
↗ example as a template. Change to this directory to continue.
Create a new GitHub repository by visiting repo.new ↗. After creating a new repository, prepare and push your local application to GitHub by running the following commands in your terminal:
To deploy your site to Pages:
- Log in to the Cloudflare dashboard ↗ and select your account.
- In Account Home, select Workers & Pages > Create application > Pages > Connect to Git.
- Select the new GitHub repository that you created and, in the Set up builds and deployments section, select Next.js (Static HTML Export) as your Framework preset. Your selection will provide the following information.
Configuration option | Value |
---|---|
Production branch | main |
Build command | npx next build |
Build directory | out |
After configuring your site, you can begin your first deploy. Cloudflare Pages will install next
, your project dependencies, and build your site before deploying it.
After deploying your site, you will receive a unique subdomain for your project on *.pages.dev
.
Every time you commit new code to your Next.js site, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.
For the complete guide to deploying your first site to Cloudflare Pages, refer to the Get started guide.