What You Are Learning
This tutorial explains the deployment workflow for an Astro Starlight site.
You will learn how to:
- Build the site locally.
- Preview the production build.
- Understand the
dist/output folder. - Deploy to Vercel.
- Deploy to Netlify.
- Deploy to Cloudflare Pages or Workers.
- Use environment variables safely.
- Fix common build and deployment errors.
Big Picture Mental Model
Deployment means turning your source code into a published website.
Source files
↓
npm install
↓
npm run build
↓
dist/ folder
↓
Hosting platform
↓
Live website URL
For a mostly static Astro Starlight site, the most important settings are usually:
Build command: npm run build
Output directory: dist
Deployment Vocabulary
| Term | Meaning |
|---|---|
| Build | The process of generating production files from source files. |
| Output directory | The folder that contains the final site files. For Astro, this is usually dist. |
| Static site | A site that can be served as HTML, CSS, JavaScript, and assets without a custom server. |
| Preview deployment | A test deployment usually created from a branch or pull request. |
| Production deployment | The main public version of the site. |
| Environment variable | A setting or secret stored outside your source code. |
Check Your Scripts
Open:
package.json
You should see scripts like:
{
"scripts": {
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview"
}
}
These scripts are the foundation of the workflow:
npm run dev local development
npm run build production build
npm run preview preview production build locally
Build Locally Before Deploying
Run:
npm install
npm run build
If the build succeeds, Astro creates:
dist/
Do not skip this step. A site can work in development but fail in production because of broken imports, invalid MDX, incorrect image paths, or missing environment variables.
Preview the Production Build
Run:
npm run preview
This serves the built site locally. Use this to check:
- Home page loads.
- Sidebar links work.
- Images load.
- MDX components render.
- Custom CSS is applied.
- No routes are missing.
Git Workflow Before Deployment
Most platforms deploy from GitHub, GitLab, or Bitbucket.
git status
git add .
git commit -m "Prepare Astro Starlight site for deployment"
git push
After you connect the repository to a host, future pushes usually trigger new deployments automatically.
General Static Deployment Settings
| Setting | Value |
|---|---|
| Build command | npm run build |
| Output directory | dist |
| Install command | npm install or platform default |
| Node version | Use a current supported Node version compatible with Astro. |
Deploy to Vercel
Vercel works well for Astro and Starlight sites.
- Push your project to GitHub, GitLab, or Bitbucket.
- Sign in to Vercel.
- Create a new project.
- Import the repository.
- Confirm the project settings.
- Deploy.
Common settings:
Framework preset: Astro
Build command: npm run build
Output directory: dist
Vercel usually detects Astro automatically, but always check the build command and output directory.
Deploy to Netlify
Netlify is also a strong choice for static Astro/Starlight sites.
- Push your project to GitHub, GitLab, or Bitbucket.
- Sign in to Netlify.
- Create a new site from Git.
- Select the repository.
- Set build options.
- Deploy.
Common settings:
Build command: npm run build
Publish directory: dist
You can also create a netlify.toml file:
[build]
command = "npm run build"
publish = "dist"
Deploy to Cloudflare Pages
For a static Astro Starlight site, Cloudflare Pages can deploy from a Git repository.
- Push your project to a Git provider.
- Open Cloudflare dashboard.
- Create a Pages project.
- Connect your repository.
- Set the build command and output directory.
- Deploy.
Common static settings:
Build command: npm run build
Output directory: dist
Some newer Cloudflare workflows use Workers and Wrangler. For a basic static documentation site, Pages-style Git deployment is usually simpler.
Deploy to Cloudflare Workers with Wrangler
Cloudflare also supports deploying Astro output with Wrangler, especially when using Workers-oriented workflows.
Install Wrangler:
npm install wrangler@latest --save-dev
A static wrangler.jsonc can point to the dist folder:
{
"name": "my-astro-starlight-site",
"compatibility_date": "2026-05-13",
"assets": {
"directory": "./dist"
}
}
Preview and deploy:
npx astro build && npx wrangler dev
npx astro build && npx wrangler deploy
Use this route when you specifically want Cloudflare Workers features or a Wrangler-based workflow.
Environment Variables
Environment variables store settings outside your source code.
PUBLIC_SITE_NAME="Astro Starlight Tutorial Site"
PUBLIC_ANALYTICS_ID="example-id"
SECRET_API_KEY="do-not-expose-this"
Astro exposes environment variables prefixed with PUBLIC_ to browser code. Do not put secrets in public variables.
| Variable Type | Use For |
|---|---|
PUBLIC_ variables |
Safe values the browser can see. |
| Secret variables | Server-only API keys and private tokens. |
Static Site vs Server Features
Most Starlight documentation sites can be deployed as static sites. That means no custom adapter is needed.
Static docs site:
npm run build
output: dist
deploy dist
If you add server-rendered routes, API routes, authentication, or runtime database calls, you may need an adapter for the hosting platform.
Mostly content and docs:
static output is usually best
Runtime server features:
consider an adapter
Base URL and Site URL
If your site is deployed at the root of a domain, the default setup is usually fine:
https://example.com/
If your site is deployed under a subpath, such as GitHub Pages, you may need a base setting:
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
export default defineConfig({
site: 'https://example.com',
base: '/my-docs/',
integrations: [
starlight({
title: 'My Docs',
}),
],
});
For Vercel, Netlify, and Cloudflare Pages custom domains, you usually do not need base.
Custom Domains
After deployment, most platforms let you add a custom domain.
example.com
www.example.com
docs.example.com
General process:
- Add the domain in the hosting platform dashboard.
- Update DNS records at the domain registrar.
- Wait for DNS propagation.
- Confirm HTTPS is active.
Deployment Checklist
[ ] npm install works
[ ] npm run dev works
[ ] npm run build works
[ ] npm run preview works
[ ] dist folder is created
[ ] Homepage loads
[ ] Sidebar links work
[ ] Images load
[ ] Custom CSS loads
[ ] Environment variables are configured
[ ] Repository is pushed to GitHub/GitLab/Bitbucket
[ ] Hosting platform build command is correct
[ ] Hosting platform output directory is dist
Common Problem: Build Fails Locally
Run:
npm install
npm run build
Common causes:
- Invalid Markdown or MDX.
- Broken component import path.
- Missing package.
- Invalid frontmatter.
- Schema validation error.
Fix the local build before trying to deploy.
Common Problem: Deployment Builds but Site Is Blank
Check:
- Output directory is
dist. - Build command is
npm run build. - The homepage exists.
- There is no incorrect
basesetting. - Assets are referenced with correct paths.
Common Problem: Images Missing After Deployment
If images are in public/images/, reference them like this:

Do not reference local computer paths:
Bad:
C:\Users\Name\Desktop\map.png
Good:
/images/map.png
Common Problem: Environment Variable Undefined
Check:
- The variable exists in the hosting platform settings.
- The variable name matches exactly.
- You redeployed after adding the variable.
- Browser-visible variables use the
PUBLIC_prefix.
Common Problem: Wrong Node Version
If a platform uses an old Node version, the build may fail. You can specify a Node version in package.json:
{
"engines": {
"node": ">=20.0.0"
}
}
Use a Node version supported by your current Astro version and hosting platform.
Preview Deployments
Preview deployments are temporary builds usually made from branches or pull requests.
main branch
→ production deployment
feature branch
→ preview deployment
Use preview deployments to test:
- New lessons.
- Sidebar changes.
- Theme changes.
- Content collection changes.
- Large world bible restructures.
Recommended Workflow for Ongoing Updates
1. Create or edit content locally.
2. Run npm run dev.
3. Check pages in the browser.
4. Run npm run build.
5. Run npm run preview.
6. Commit changes.
7. Push to GitHub.
8. Check preview deployment.
9. Merge or push to main.
10. Check production deployment.
Which Platform Should You Use?
| Platform | Good For |
|---|---|
| Vercel | Simple Git-based deploys, frontend projects, preview deployments. |
| Netlify | Static sites, forms, redirects, simple project dashboards. |
| Cloudflare Pages | Fast static hosting, global edge network, Cloudflare ecosystem. |
| Cloudflare Workers | More advanced edge/server workflows with Wrangler. |
| Traditional web host | Manual upload of the dist folder. |
For a beginner Astro Starlight site, Vercel or Netlify are usually the easiest. Cloudflare Pages is also excellent, especially if you already use Cloudflare DNS.
Manual Deployment
You can also deploy manually by uploading the built files.
npm run build
Then upload the contents of:
dist/
Use this method if your host only supports traditional file upload. Do not upload the project source files unless your host expects them.
Best Practices
- Always run
npm run buildbefore deploying important changes. - Use
npm run previewto test the production build locally. - Keep deployment settings simple for static Starlight sites.
- Use
distas the output directory unless your project is intentionally configured otherwise. - Do not commit secrets to Git.
- Use preview deployments for large changes.
- Check custom domains after DNS changes.
- Keep dependencies updated, but test builds after updates.
Mini Project: Deploy a Starlight Site
- Run
npm install. - Run
npm run dev. - Check the site locally.
- Run
npm run build. - Run
npm run preview. - Commit your changes.
- Push to GitHub.
- Import the repo into Vercel, Netlify, or Cloudflare Pages.
- Set build command to
npm run build. - Set output directory to
dist. - Deploy.
- Open the live URL and test the site.
Cheat Sheet
| Task | Command or Setting |
|---|---|
| Install dependencies | npm install |
| Local development | npm run dev |
| Build production site | npm run build |
| Preview production build | npm run preview |
| Output directory | dist |
| Vercel build command | npm run build |
| Netlify publish directory | dist |
| Cloudflare Pages output | dist |
| Wrangler deploy | npx astro build && npx wrangler deploy |
Simple Rule of Thumb
If it is a normal Starlight docs site:
build with npm run build
deploy the dist folder
If it needs server features:
check whether your host needs an Astro adapter
If something breaks after deployment:
test npm run build and npm run preview locally first