Deploy to Netlify
Deploy your Specra documentation to Netlify for static hosting with edge functions
Deploy to Netlify
Netlify provides powerful static hosting with features like instant rollbacks, split testing, and edge functions. It's a great choice for documentation sites.
Why Netlify?
- One-click deploy - Connect and deploy in minutes
- Continuous deployment - Auto-deploy on git push
- Instant rollbacks - Restore previous versions instantly
- Edge functions - Run code at the edge
- Forms & identity - Built-in form handling and auth
- Free tier - Generous limits for documentation
Quick Deploy
Configure for Static Export
1{2 "deployment": {3 "target": "static",4 "basePath": "",5 "customDomain": false6 }7}Create netlify.toml
1[build]2 command = "npm run build:export"3 publish = "out"4 5[build.environment]6 NODE_VERSION = "20"7 8[[redirects]]9 from = "/*"10 to = "/index.html"11 status = 200This tells Netlify how to build and what to publish.
Deploy
Option 1: Web UI
- Go to netlify.com
- Click "Add new site" → "Import an existing project"
- Connect your Git provider
- Select your repository
- Click "Deploy site"
Option 2: Netlify CLI
1npm install -g netlify-cli2netlify deploy --prodConfiguration
Build Settings
Netlify auto-detects settings, but you can customize:
| Setting | Value |
|---|---|
| Build command | npm run build:export |
| Publish directory | out |
| Node version | 20 (set in netlify.toml) |
Environment Variables
Add environment variables in the Netlify dashboard:
Go to Site Settings
Add Variables
MEILISEARCH_HOST=https://search.example.com
MEILISEARCH_API_KEY=your-search-key
NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX
Redeploy
Custom Domain
Add your own domain to your Netlify site:
Add Domain
- Go to Domain settings
- Click "Add custom domain"
- Enter your domain (e.g.,
docs.example.com) - Click "Verify"
Configure DNS
Option 1: Use Netlify DNS (Recommended)
- Point your domain's nameservers to Netlify
- Netlify manages all DNS records
- Automatic SSL certificate
Option 2: Use External DNS
For subdomain:
Type: CNAME
Name: docs
Value: your-site.netlify.app
For apex domain:
Type: A
Name: @
Value: 75.2.60.5
Enable HTTPS
Check Domain settings → HTTPS for status.
Deploy Previews
Netlify creates preview deployments for every pull request:
What you get:
- Unique URL for each PR
- Automatic updates when you push
- Deploy preview link in PR comments
- Perfect for reviewing changes
Configure Deploy Previews
Control when previews are created:
1[context.deploy-preview]2 command = "npm run build:export"3 4[context.branch-deploy]5 command = "npm run build:export"Advanced Features
Redirect Rules
Add redirects in netlify.toml:
1# Redirect old URLs2[[redirects]]3 from = "/old-page"4 to = "/new-page"5 status = 3016 7# SPA fallback8[[redirects]]9 from = "/*"10 to = "/index.html"11 status = 20012 13# Country-based redirects14[[redirects]]15 from = "/docs"16 to = "/en/docs"17 status = 30218 conditions = {Country = ["US"]}Headers
Add custom headers:
1[[headers]]2 for = "/*"3 [headers.values]4 X-Frame-Options = "DENY"5 X-XSS-Protection = "1; mode=block"6 Content-Security-Policy = "default-src 'self'"7 8[[headers]]9 for = "/assets/*"10 [headers.values]11 Cache-Control = "public, max-age=31536000, immutable"Edge Functions
Run code at the edge for dynamic functionality:
Create netlify/edge-functions/hello.ts:
1export default async (request: Request) => {2 return new Response("Hello from the edge!")3}4 5export const config = {6 path: "/api/hello"7}Split Testing
Test different versions of your docs:
- Go to Split testing
- Click "Start a test"
- Select branches to compare
- Set traffic split (e.g., 50/50)
Great for testing new documentation layouts or content.
Build Plugins
Extend your build with Netlify plugins:
1[[plugins]]2 package = "@netlify/plugin-lighthouse"3 4[[plugins]]5 package = "netlify-plugin-checklinks"Install plugins:
1npm install -D @netlify/plugin-lighthouse netlify-plugin-checklinksDeployment Contexts
Different configs for different branches:
1# Production (main branch)2[context.production]3 command = "npm run build:export"4 [context.production.environment]5 NODE_ENV = "production"6 7# Staging branch8[context.staging]9 command = "npm run build:export"10 [context.staging.environment]11 NODE_ENV = "staging"12 13# Deploy previews (PRs)14[context.deploy-preview]15 command = "npm run build:export -- --debug"Performance Optimization
Asset Optimization
Netlify automatically optimizes:
- Image compression
- Bundle minification
- Brotli compression
Enable in Build & deploy → Post processing.
Caching
Configure cache headers:
1[[headers]]2 for = "/_app/immutable/*"3 [headers.values]4 Cache-Control = "public, max-age=31536000, immutable"5 6[[headers]]7 for = "/images/*"8 [headers.values]9 Cache-Control = "public, max-age=604800"Prerendering
For better SEO, enable prerendering:
1[[plugins]]2 package = "@sveltejs/adapter-netlify"Forms
Add forms to your documentation:
1<form name="contact" method="POST" data-netlify="true">2 <input type="text" name="name" />3 <input type="email" name="email" />4 <textarea name="message"></textarea>5 <button type="submit">Send</button>6</form>Netlify automatically handles form submissions. View responses in Forms tab.
Analytics
Enable Netlify Analytics for visitor insights:
- Go to Analytics tab
- Click "Enable Analytics"
- Costs $9/month (optional)
Shows:
- Page views
- Top pages
- Traffic sources
- Geographic data
CI/CD Integration
GitHub Actions + Netlify
Deploy from GitHub Actions for more control:
1name: Deploy to Netlify2 3on:4 push:5 branches: [main]6 7jobs:8 deploy:9 runs-on: ubuntu-latest10 steps:11 - uses: actions/checkout@v412 13 - name: Setup Node14 uses: actions/setup-node@v415 with:16 node-version: '20'17 18 - name: Install dependencies19 run: npm ci20 21 - name: Build22 run: npm run build:export23 24 - name: Deploy to Netlify25 uses: nwtgck/actions-netlify@v226 with:27 publish-dir: './out'28 production-deploy: true29 env:30 NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}31 NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}Get your auth token and site ID from Netlify dashboard.
Troubleshooting
Build Fails
Check build logs:
- Go to Deploys
- Click failed deploy
- View deploy log
Common issues:
- Node version mismatch (set in
netlify.toml) - Missing dependencies (use
npm cinotnpm install) - Environment variables not set
Assets 404
Ensure netlify.toml has the SPA redirect:
1[[redirects]]2 from = "/*"3 to = "/index.html"4 status = 200Functions Not Working
Check function logs:
- Go to Functions tab
- Click your function
- View logs
Ensure function path matches config:
1export const config = {2 path: "/api/hello" // Must match your route3}Custom Domain SSL Issues
- Wait 24 hours for DNS propagation
- Verify DNS records with
digornslookup - Check HTTPS status in Domain settings
- Try re-provisioning certificate
Rollbacks
Instantly rollback to a previous deployment:
- Go to Deploys
- Find the working version
- Click "Publish deploy"
Your site reverts immediately. No waiting for builds.
Monitoring
Deploy Notifications
Get notified when deploys succeed or fail:
- Go to Site settings → Build & deploy → Deploy notifications
- Add notification (Email, Slack, webhook)
- Choose events (deploy started, succeeded, failed)
Status Badge
Add a deploy status badge to your README:
1[](https://app.netlify.com/sites/SITE_NAME/deploys)Pricing
Netlify's free tier includes:
- 300 build minutes/month
- 100GB bandwidth/month
- Unlimited sites
- Deploy previews
- HTTPS
- Forms (100 submissions/month)
Upgrade to Pro ($19/month) for:
- More bandwidth and build minutes
- Analytics
- Team collaboration
- Priority support
Best Practices
Use netlify.toml - Version control your build config
Enable deploy previews - Review changes before merging
Set up notifications - Know immediately when deploys fail
Use environment variables - Keep secrets out of code
Configure redirects - Handle URL changes properly
Monitor analytics - Understand how users navigate your docs
Test locally - Run npm run build:export && npx serve out first