Vue.js project deployment
Build production version
Vite Project
The built file is indistin the directory.
Environment variables
Static hosting platform
1. Vercel (recommended)
Features:
- Zero configuration deployment
- Automatic HTTPS
- Global CDN
- Automatic preview deployment
Deployment steps:
Or integrated via GitHub:
- Visit vercel.com
- Import GitHub repository
- Automatic deployment
2. Netlify
Deployment steps:
Configuration file:
3. GitHub Pages
Deployment script:
Vite Configuration:
4. Cloudflare Pages
- Log in to Cloudflare Pages
- Connect to GitHub repository
- Configure build commands:
npm run build - Configure the output directory:
dist - Deployment
Server deployment
Nginx configuration
Docker deployment
Dockerfile:
docker-compose.yml:
Build and run:
Node.js Server
Express Server
package.json:
CDN Acceleration
Use CDN to host static resources
Commonly used CDN services
- jsDelivr: Free and fast
- unpkg: npm package CDN
- cdnjs: Popular library CDN
- Alibaba Cloud CDN: fast domestic access
- Tencent Cloud CDN: Fast domestic access
Performance optimization
1. Code splitting
2. Compression and obfuscation
3. Gzip compression
4. Image optimization
Monitoring and Analysis
1. Performance monitoring
2. Error monitoring
3. Using Sentry
CI/CD Automation
GitHub Actions
GitLab CI
Domain name and HTTPS
1. Configure domain name
Add DNS records at your domain provider:
2. Configure HTTPS
Use Let's Encrypt free certificates:
Deployment Checklist
Before building
- ✅ Remove console.log
- ✅ Check environment variables
- ✅ Update dependency version
- ✅ Run the test
- ✅ Check for build warnings
After deployment
- ✅ Check whether all pages are working properly
- ✅ Test route jump
- ✅ Check API calls
- ✅ Test form submission
- ✅ Check mobile adaptation
- ✅ Test different browsers
- ✅ Check SEO tags
- ✅ Test performance indicators
Monitoring
- ✅ Set up error monitoring
- ✅ Configure performance monitoring
- ✅ Set up log collection
- ✅ Configure alarm notifications
FAQ
1. Refresh 404
Cause: The server is not configured with SPA routing support
SOLUTION: Configure the server to redirect all requests to index.html
2. Static resources 404
Cause: Base path configuration error
Solution: Check the base configuration in vite.config.js
3. Environment variables do not take effect
Cause: Wrong environment variable name or not rebuilt
Solution: Make sure the variable name ends withVITE_Beginning, rebuilding
Summarize
- Choose the right hosting platform (Vercel, Netlify, GitHub Pages)
- Configure server to support SPA routing
- Containerized deployment using Docker
- Enable Gzip compression and CDN acceleration
- Configure HTTPS and custom domain name
- Set up CI/CD automated deployment
- Add monitoring and error tracking
- Optimize performance and loading speed
Next step
Next, learn Best Practices to learn about the best practices for Vue development.