This guide explains how to deploy the Markdown Editor as a static site.
First, ensure all dependencies are installed and build the project:
npm install
npm run buildThis creates a dist/ directory with all static files ready for deployment.
For local testing, you can use any static file server:
# Using Python
cd dist
python -m http.server 8000
# Using Node.js http-server
npx http-server dist -p 8000
# Using PHP
cd dist
php -S localhost:8000server {
listen 80;
server_name your-domain.com;
root /path/to/markdown-editor/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
# Cache static assets
location /assets/ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}Place this in the dist/ directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# Cache static assets
<FilesMatch "\.(js|css|woff|woff2|ttf|png|jpg|jpeg|gif|ico)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>- Connect your GitHub repository
- Build command:
npm run build - Publish directory:
dist
- Import your project
- Framework preset: Vite
- Build command:
npm run build - Output directory:
dist
- Build locally:
npm run build - Push
dist/contents togh-pagesbranch - Or use GitHub Actions:
name: Deploy to GitHub Pages
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run build
- uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist# Build
npm run build
# Upload to S3
aws s3 sync dist/ s3://your-bucket-name --delete
# Invalidate CloudFront cache
aws cloudfront create-invalidation --distribution-id YOUR_DIST_ID --paths "/*"Create a Dockerfile:
FROM nginx:alpine
COPY dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.confCreate nginx.conf:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
}Build and run:
docker build -t markdown-editor .
docker run -p 80:80 markdown-editorTo deploy the application in a subdirectory (e.g., https://example.com/markdown-editor/):
-
Copy
.env.exampleto.env:cp .env.example .env
-
Edit
.envto set your base URL:# For root deployment (default) VITE_BASE_URL=/ # For sub-site deployment VITE_BASE_URL=/markdown-editor/
-
Build the application:
npm run build
The base URL is configured at build time and cannot be changed after deployment. Make sure to set the correct VITE_BASE_URL before building.
The app runs entirely in the browser. No CORS configuration needed.
Recommended security headers for production:
Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: blob:;
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
The production build includes:
- Minified JavaScript and CSS
- Code splitting for better caching
- Optimized fonts (KaTeX for math rendering)
- Tree-shaking to remove unused code
After deployment, verify:
- App loads correctly
- Editor and preview sync properly
- Export features work (PDF, DOCX, Markdown)
- Dark mode toggles and persists
- Copy functionality works
- Keyboard shortcuts function
- Check console for errors
- Verify all files uploaded correctly
- Check base URL configuration
The ~3.5MB main bundle includes:
- Rich text editing libraries
- PDF generation
- DOCX generation
- Syntax highlighting
- Math rendering
This is normal for a feature-rich editor.
Ensure your web server redirects all routes to index.html (SPA requirement).
- Enable gzip/brotli compression on your web server
- Use a CDN for global distribution
- Set appropriate cache headers for assets
- Consider lazy-loading features if needed