Deploy to Netlify
Deploy Clarity documentation to Netlify for instant deployments and branch previews
Deploy to Netlify
Deploy your Clarity documentation to Netlify for fast deployments, branch previews, and excellent JAMstack support.
Why Netlify?
- ⚡ Instant deployments (30-90 seconds)
- 🔀 Branch previews for every branch
- 🆓 Generous free tier
- 🔧 Built-in forms and serverless functions
- 🌍 Global CDN
Prerequisites
- Netlify account (sign up free)
- Your Clarity repository on GitHub/GitLab/Bitbucket
- Git repository with committed changes
Step 1: Prepare Your Project
Configure Environment Variables
Edit .env in your project root:
# Site Configuration
PUBLIC_SITE_NAME=My Documentation
PUBLIC_SITE_DESCRIPTION=Documentation for my project
PUBLIC_SITE_URL=https://my-docs.netlify.app
PUBLIC_BASE_PATH=/
# GitHub Integration (optional)
CLARITY_GITHUB_REPO=yourusername/repo-name
CLARITY_GITHUB_BRANCH=main
CLARITY_DOCS_PATH=src/content/docs
Test Build Locally
pnpm build
pnpm preview
Step 2: Create netlify.toml
Create netlify.toml in your project root:
[build]
command = "pnpm build"
publish = "dist"
[build.environment]
NODE_VERSION = "20"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
Commit this file:
git add netlify.toml
git commit -m "Add Netlify configuration"
git push
Step 3: Connect to Netlify
Option A: Using Netlify Dashboard (Recommended)
- Go to app.netlify.com
- Click Add new site → Import an existing project
- Choose your Git provider (GitHub/GitLab/Bitbucket)
- Select your Clarity repository
- Configure build settings (see below)
- Click Deploy site
Option B: Using Netlify CLI
# Install Netlify CLI
npm install -g netlify-cli
# Login
netlify login
# Initialize and deploy
cd my-docs
netlify init
# Follow prompts to connect repository
Step 4: Configure Build Settings
Netlify should auto-detect settings, but verify:
Build command: pnpm build
Publish directory: dist
Functions directory: (leave empty)
Step 5: Add Environment Variables
In your Netlify site settings:
- Go to Site settings → Environment variables
- Click Add a variable
- Add these variables:
| Key | Value |
|---|---|
CLARITY_GITHUB_REPO | username/repo |
CLARITY_GITHUB_BRANCH | main |
CLARITY_DOCS_PATH | src/content/docs |
Click Save.
Step 6: Deploy
Your first deploy starts automatically. Once complete:
Your site is available at: https://random-name-123.netlify.app
Customize Site Name
- Go to Site settings → General → Site details
- Click Change site name
- Enter:
my-docs(becomesmy-docs.netlify.app)
Automatic Deployments
Netlify automatically deploys:
Production Deployments
- Every push to your main branch
- Deploys to your production URL
Branch Previews
- Every branch gets its own preview URL
- Perfect for testing features
# Create feature branch
git checkout -b new-feature
# Make changes and push
git add .
git commit -m "Add new feature"
git push origin new-feature
# Netlify creates preview URL automatically!
Custom Domain Setup
Add Domain
- Go to Domain settings → Add custom domain
- Enter your domain:
docs.yourdomain.com - Click Verify
Configure DNS
Option A: Use Netlify DNS (Recommended)
- Transfer nameservers to Netlify
- Netlify handles all DNS records automatically
Option B: External DNS
Add CNAME record at your DNS provider:
Type: CNAME
Name: docs
Value: your-site.netlify.app
For apex domain:
Type: A
Name: @
Value: 75.2.60.5
Type: CNAME
Name: www
Value: your-site.netlify.app
Enable HTTPS
- Go to Domain settings → HTTPS
- Click Verify DNS configuration
- Click Provision certificate
- Wait for SSL to activate (can take up to 24 hours)
Update Configuration
PUBLIC_SITE_URL=https://docs.yourdomain.com
Redeploy for changes to take effect.
Deploy Contexts
Netlify supports different contexts:
Production
[context.production.environment]
PUBLIC_SITE_URL = "https://docs.yourdomain.com"
Branch Deploys
[context.branch-deploy.environment]
PUBLIC_SITE_URL = "https://preview.netlify.app"
Deploy Previews
[context.deploy-preview.environment]
PUBLIC_SITE_URL = "https://deploy-preview.netlify.app"
Advanced Configuration
Redirect Rules
Add to netlify.toml:
[[redirects]]
from = "/old-path"
to = "/new-path"
status = 301
[[redirects]]
from = "/docs/*"
to = "/documentation/:splat"
status = 302
Headers
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "SAMEORIGIN"
X-XSS-Protection = "1; mode=block"
X-Content-Type-Options = "nosniff"
Build Plugins
Add plugins for optimization:
[[plugins]]
package = "@netlify/plugin-lighthouse"
Post-Processing
[build.processing]
skip_processing = false
[build.processing.css]
bundle = true
minify = true
[build.processing.js]
bundle = true
minify = true
[build.processing.html]
pretty_urls = true
Branch Previews
Enable branch previews for all branches:
- Go to Site settings → Build & deploy → Branches
- Set branch deploys to All
- Every push to any branch creates a preview
Access previews:
https://branch-name--site-name.netlify.app
Deploy Previews for Pull Requests
When someone opens a PR:
- Netlify builds and deploys a preview
- Status check added to PR with preview link
- Preview updates with each push
- Merge → automatic production deployment
Monitoring & Analytics
Netlify Analytics (Paid)
Enable server-side analytics:
- Go to Analytics tab
- Click Enable analytics ($9/month)
- View pageviews, bandwidth, and more
Benefits:
- No client-side scripts
- 100% accurate (server-side)
- No impact on performance
Troubleshooting
Build Fails
Check deploy logs:
- Go to Deploys tab
- Click failed deploy
- View deploy log
Common issues:
- Missing
package.jsonscripts - Wrong Node version → Set in
netlify.toml - Environment variables missing
Assets Not Loading
Cause: Base path or redirect issues
Solution: Ensure netlify.toml includes:
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
Slow Builds
Optimize:
- Enable build cache
- Use
pnpminstead ofnpm - Reduce dependencies
Check build time:
[build]
command = "pnpm build"
publish = "dist"
[build.environment]
NODE_VERSION = "20"
NPM_FLAGS = "--prefer-offline"
Custom Domain Not Working
Solutions:
- Wait 24-48 hours for DNS propagation
- Verify DNS records with
digornslookup - Clear browser cache
- Check Netlify DNS checker
Best Practices
1. Use Branch Deploys
Test features in isolated environments before merging.
2. Deploy Previews
Enable for all PRs to review changes safely.
3. Environment Variables
Store secrets in Netlify, never in code.
4. Optimize Builds
Use caching and minimize dependencies.
5. Monitor Performance
Use Netlify Analytics or Google Analytics.
Pricing
Free Tier Includes:
- 100 GB bandwidth/month
- 300 build minutes/month
- Unlimited sites
- Custom domains
- Automatic SSL
- Deploy previews
Pro Tier ($19/month):
- 400 GB bandwidth
- 25,000 build minutes
- Team collaboration
- Analytics
- Priority support
Next Steps
- Configure Clarity for your team
- Write documentation content
- Set up authentication (optional)
- Explore components for rich content
Resources
Was this page helpful?
Thank you for your feedback!