Host your Docusaurus on Vercel - howto

Crafting seamless user experiences with a passion for headless CMS, Vercel deployments, and Cloudflare optimization. I'm a Full Stack Developer with expertise in building modern web applications that are blazing fast, secure, and scalable. Let's connect and discuss how I can help you elevate your next project!
Here's a step-by-step tutorial to host your Docusaurus documentation on Vercel using GitHub, with automatic deployments:
Step 1: Prepare Your Docusaurus Project
- Install Docusaurus (if not already created):
npx create-docusaurus@latest my-course classic
cd my-course
- Organize your Markdown files:
# Replace default docs with your course content
rm -rf docs/*
cp -R /path/to/your/md/files/* docs/
- Configure
docusaurus.config.js:
module.exports = {
title: 'My Online Course',
url: 'https://your-course.vercel.app',
baseUrl: '/',
organizationName: 'your-github-username',
projectName: 'your-repo-name',
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
routeBasePath: '/', // Serve docs at root
sidebarPath: require.resolve('./sidebars.js'),
},
blog: false, // Disable blog if not needed
},
],
],
};
Step 2: Set Up GitHub Repository
- Initialize Git:
git init
git add .
git commit -m "Initial course content"
Create new GitHub repository at github.com/new
Name:
your-course-repoDo not initialize with README
Push to GitHub:
git remote add origin https://github.com/your-username/your-repo-name.git
git branch -M main
git push -u origin main
Step 3: Deploy to Vercel
Sign up at vercel.com using GitHub account
Click "Add New Project" > "Import Project"
Select your GitHub repository
Configure project settings:
Project Name: your-course-name
Build Command:
npm run buildOutput Directory:
buildInstall Command:
npm install

- Click "Deploy" - First build will start automatically
Step 4: Configure Automatic Deployments
Enable GitHub integration:
Go to Vercel project > Settings > Git
Enable "Automatically deploy on commit"
Create
vercel.jsonfor custom routing:
{
"cleanUrls": true,
"trailingSlash": false,
"rewrites": [
{ "source": "/(.*)", "destination": "/$1" }
]
}
Step 5: Organize Course Structure
- Edit
sidebars.jsto create navigation:
module.exports = {
myCourseSidebar: [
{
type: 'category',
label: 'Module 1: Introduction',
items: ['intro', 'getting-started'],
},
{
type: 'category',
label: 'Module 2: Core Concepts',
items: ['concepts-1', 'concepts-2', 'exercises'],
},
// Add more modules...
],
};
- Add metadata to Markdown files:
---
title: Getting Started
sidebar_position: 2
tags: [beginner, setup]
---
Step 6: Add Course Features
- Install useful plugins:
npm install @docusaurus/theme-live-codeblock @docusaurus/plugin-ideal-image
- Enable in
docusaurus.config.js:
plugins: [
'@docusaurus/theme-live-codeblock',
[
'@docusaurus/plugin-ideal-image',
{ quality: 70, max: 1030 },
],
],
Step 7: Custom Domain (Optional)
Buy domain from Namecheap/Porkbun
In Vercel project:
Go to Settings > Domains
Enter your domain (e.g.,
course.yourdomain.com)Configure DNS as instructed:
CNAME: course → cname.vercel-dns.com
Step 8: Update & Maintain
Make content changes locally
Commit and push to GitHub:
git add .
git commit -m "Updated lesson 3"
git push origin main
Vercel will automatically rebuild and deploy in 30-60 seconds
Troubleshooting Tips
Build fails: Check logs in Vercel dashboard
Missing content: Verify file paths in
sidebars.jsBroken links: Run
npx docusaurus check-linksPerformance issues: Add caching headers in
vercel.json:"headers": [ { "source": "/(.*)", "headers": [ { "key": "Cache-Control", "value": "public, max-age=3600" } ] } ]
Final Structure
my-course/
├── docs/
│ ├── module1/
│ │ ├── lesson1.md
│ │ └── lesson2.md
│ └── module2/
├── src/
│ └── css/
│ └── custom.css
├── static/
│ └── images/
├── docusaurus.config.js
├── sidebars.js
├── vercel.json
└── package.json
Access your course: https://your-course.vercel.app
Admin dashboard: https://vercel.com/your-username/your-project






