Deployment
Static Site Output
By default, Astro builds your project as a static site. This means all your pages are pre-rendered at build time into HTML files, making them incredibly fast and easy to deploy anywhere.
npm run build
The output goes to the dist/ directory, ready to be served by any static file server or CDN.
Deploying to Netlify
Netlify is an excellent choice for Astro sites. It offers continuous deployment from Git, automatic SSL, and a generous free tier.
- Push your project to a Git repository (GitHub, GitLab, or Bitbucket)
- Connect the repository in the Netlify dashboard
- Set the build command to
npm run build - Set the publish directory to
dist - Deploy!
Netlify will automatically rebuild and deploy your site whenever you push changes.
Deploying to Vercel
Vercel provides seamless deployment for Astro projects:
- Install the Vercel CLI:
npm i -g vercel - Run
vercelin your project directory - Follow the prompts to configure your project
Or connect your Git repository through the Vercel dashboard for automatic deployments.
Deploying to Cloudflare Pages
Cloudflare Pages offers global CDN distribution and fast builds:
- Connect your Git repository in the Cloudflare dashboard
- Set the build command to
npm run build - Set the output directory to
dist - Deploy
Cloudflare’s global network ensures your content loads quickly worldwide.
Custom Server Deployment
For self-hosted deployments, you can serve the dist/ directory with any web server:
# Using a simple HTTP server
npx serve dist
# Using Nginx (copy dist/ contents to your web root)
cp -r dist/* /var/www/html/
Remember to configure proper caching headers for static assets and enable gzip or Brotli compression for optimal performance.