Deploying & Hosting
There are two chairs...
Automatic rebuild and deploy options:
This method works best for scenario when you want to automatically deploy changes you made without building static web pages on your machine.
Pros
- No need to execute build command on your machine
- You can edit files with online IDE on your Git hosting
- Depending on your configuration you might get autodeploy once your website's repo gets updated
- You can add APIs and server scripts to use on your server
- Custom "Not found" page
Cons
- You need to use specific hosting with running NodeJS and deploy pipelines
- You need to understand how your deploy pipelines or CI/CD processes should be configured and work
- This method requires some resources on your server to build pages dynamically.
Make sure you DON'T have output: "export"
in your next.config.mjs
Setup deploy
- Host your app on GitHub, GitLab, BitBucket or any other Git host.
- Use Vercel or Netlify to automatically watch your repo for changes and deploy new versions
- (Alternatively) Use any NodeJS hosting and either setup CI/CD that will watch your repo changes or deploy it manually.
- Great success!
Manual build and deploy:
Pros
- No specific hosting requirements. You can go with anything that can serve static HTML files.
- No costly dynamic renders of your content
Cons
- You need to run build command yourself
- You cannot add APIs or server scripts
- No custom "Not found" page unless your hosting allows you to use custom HTML-page for this.
Make sure you DO have output: "export"
in your next.config.mjs
How to generate static pages
- Edit your content
- Run
npm run build
oryarn run build
to generate updated static pages - Upload static files from
/out
folder to your static website hosting, like GitHub Pages, surge.sh and etc. No need in running NodeJS on your host.
Please, refer to Next.js deployment documentation for more details.