How to create a static site with Next.js
Next.js is a powerful framework that supports different rendering modes, including Static Site Generation (SSG).
Advantages of static sites
Static sites offer several advantages:
- Performance - Pre-rendered pages load instantly
- SEO - Fully indexable content
- Cost - Free hosting on services like GitHub Pages
- Security - No server to attack
Basic configuration
To export a static site with Next.js, add to next.config.js:
const nextConfig = {
output: 'export',
images: {
unoptimized: true,
},
}
Generating the site
Run the command:
npm run build
This generates an out/ folder with all static files ready for deployment!
Deploy to GitHub Pages
GitHub Pages is perfect for hosting static sites for free. Just:
- Push files to the repository
- Configure GitHub Actions for automatic build
- Enable GitHub Pages in settings
And that's it! Your site will be live at username.github.io.
Conclusion
Next.js + SSG is a powerful combination for blogs and content sites. Performance, ease of development, and zero hosting cost make this an excellent choice!