Last Updated: 3/6/2026
Deployment Guide
This guide covers deploying the Snake Game to various hosting platforms.
Build Process
Before deploying, build the production bundle:
npm run buildThis creates an optimized production build in the dist/ directory.
Deployment Options
Vercel (Recommended)
Vercel provides zero-config deployment for Vite projects.
One-Click Deploy
- Push your code to GitHub
- Visit vercel.com
- Click “Import Project”
- Select your repository
- Vercel auto-detects Vite configuration
- Click “Deploy”
CLI Deploy
npm install -g vercel
vercelFollow the prompts to deploy.
Netlify
Netlify also offers seamless Vite deployment.
Deploy via Git
- Push code to GitHub/GitLab/Bitbucket
- Visit netlify.com
- Click “New site from Git”
- Select your repository
- Configure build settings:
- Build command:
npm run build - Publish directory:
dist
- Build command:
- Click “Deploy site”
Drag & Drop Deploy
- Run
npm run build - Visit app.netlify.com/drop
- Drag the
dist/folder to the upload area
GitHub Pages
Deploy to GitHub Pages with a few configuration changes.
Setup
- Update
vite.config.ts(create if it doesn’t exist):
import { defineConfig } from 'vite'
export default defineConfig({
base: '/snake-game/', // Replace with your repo name
})- Install gh-pages:
npm install --save-dev gh-pages- Add deploy script to
package.json:
{
"scripts": {
"deploy": "npm run build && gh-pages -d dist"
}
}- Deploy:
npm run deploy- Enable GitHub Pages in repository settings:
- Go to Settings → Pages
- Source:
gh-pagesbranch - Save
Your site will be available at https://<username>.github.io/snake-game/.
Static Hosting (Generic)
The built files can be deployed to any static hosting service:
- Build the project:
npm run build- Upload
dist/contents to your hosting provider:- AWS S3 + CloudFront
- Google Cloud Storage
- Azure Static Web Apps
- Cloudflare Pages
- Firebase Hosting
Docker
For containerized deployment:
Dockerfile
# Build stage
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]Build and Run
docker build -t snake-game .
docker run -p 8080:80 snake-gameAccess at http://localhost:8080.
Environment Configuration
Base URL
If deploying to a subdirectory, configure the base URL:
vite.config.ts:
import { defineConfig } from 'vite'
export default defineConfig({
base: '/your-subdirectory/',
})Custom Domain
Most platforms support custom domains:
- Vercel: Add domain in project settings
- Netlify: Add domain in site settings
- GitHub Pages: Add
CNAMEfile topublic/directory
Performance Optimization
Compression
Enable gzip/brotli compression on your server:
- Nginx: Enable
gzipin config - Vercel/Netlify: Enabled by default
Caching
Set appropriate cache headers:
location / {
# Cache static assets for 1 year
location ~* \.(js|css|png|jpg|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Don't cache HTML
location ~* \.html$ {
expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
}CDN
Use a CDN for global distribution:
- Vercel and Netlify include CDN by default
- For custom hosting, consider Cloudflare or AWS CloudFront
Monitoring
Analytics
Add analytics to track usage:
index.html:
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>Error Tracking
Integrate error tracking (e.g., Sentry):
npm install @sentry/browsersrc/main.ts:
import * as Sentry from '@sentry/browser'
Sentry.init({
dsn: 'YOUR_SENTRY_DSN',
environment: 'production',
})Continuous Deployment
GitHub Actions
Automate deployment with GitHub Actions:
.github/workflows/deploy.yml:
name: Deploy
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: ./distTroubleshooting
404 Errors
- Verify
baseURL invite.config.tsmatches deployment path - Check that all assets are in
dist/after build
Blank Page
- Check browser console for errors
- Verify paths in
index.htmlare correct - Ensure all dependencies are in
dependencies(notdevDependencies)
Performance Issues
- Enable compression on server
- Use CDN for static assets
- Minimize bundle size (check with
npm run build -- --analyze)
Security
Content Security Policy (CSP)
Add CSP headers to prevent XSS:
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';">HTTPS
- Vercel, Netlify, and GitHub Pages provide free HTTPS
- For custom hosting, use Let’s Encrypt for free SSL certificates
Rollback
Most platforms support instant rollback:
- Vercel: Click “Rollback” on any previous deployment
- Netlify: Select a previous deploy and click “Publish deploy”
- GitHub Pages: Revert the commit or redeploy from an earlier commit