Building for Production
Run the build command to generate the static site:
npm run build
This does two things:
- Astro compiles all pages into static HTML/CSS/JS in the
dist/directory. - The
postbuildscript runs Pagefind to generate the search index indist/pagefind/.
Pre-Deployment Checklist
Before deploying, verify these settings:
-
siteinastro.config.mjsis set to your production domain -
siteUrlinsrc/lib/site-config.tsmatches your domain -
homepageinpackage.jsonis updated -
public/robots.txthas the correct sitemap URL - All placeholder links in
site-config.tsare replaced with real URLs
Hosting Platforms
The dist/ folder can be deployed to any static hosting provider. Here are common options:
Cloudflare Pages
Connect your Git repository to Cloudflare Pages. Set the build command to npm run build and the output directory to dist.
Netlify
Connect your repository and configure:
- Build command:
npm run build - Publish directory:
dist
Vercel
Import your repository and set the framework preset to “Astro” or configure manually:
- Build command:
npm run build - Output directory:
dist
GitHub Pages
Use a GitHub Actions workflow to build and deploy. Set the output directory to dist in your workflow configuration.
Manual / S3 + CDN
Run npm run build locally and upload the contents of dist/ to your hosting provider or S3 bucket. Configure your CDN to serve from the bucket.
Previewing Before Deploy
To test the production build locally before deploying:
npm run preview
This serves the dist/ directory on a local server so you can verify everything works as expected, including Pagefind search.
Troubleshooting
Search Not Working After Deploy
Make sure the postbuild script ran successfully. The dist/pagefind/ directory should exist and contain index files. Some hosting platforms may not run postbuild automatically — in that case, use npm run build && npx pagefind --site dist as your build command.
Wrong URLs in Sitemap or Meta Tags
Double-check that the site value in astro.config.mjs matches your actual production URL, including the protocol (https://).