Once you’ve built your static site, you’ll want to deploy it so the world can see it. This guide covers several popular deployment options.
Before deploying, make sure to build your site:
npm run build
This creates all the static files in the public/ directory.
GitHub Pages is a free hosting service for static sites.
public/ folder to the gh-pages branch:cd public
git init
git add .
git commit -m "Deploy to GitHub Pages"
git branch -M gh-pages
git remote add origin https://github.com/username/repo.git
git push -u origin gh-pages
Netlify offers continuous deployment from Git repositories.
netlify.toml configuration:[build]
command = "npm run build"
publish = "public"
Vercel provides excellent performance and easy deployment.
npm install -g vercel
vercel --prod
You can host on any web server:
npm run buildpublic/ folder to your web serverserver {
listen 80;
server_name yourdomain.com;
root /var/www/html/public;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Before deploying, update your src/config.js:
const config = {
// ... other settings
siteUrl: "https://yourdomain.com", // Update this!
// ...
};
This ensures your RSS feed and sitemap have the correct URLs.
/rss.xml/sitemap.xmlSet up automated builds whenever you push new content:
Example GitHub Action:
name: Deploy
on:
push:
branches: [ main ]
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm install
- run: npm run build
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
Happy deploying!