Build Process
Music Store uses Vite as its build tool for fast and optimized production builds.Build Configuration
Building for Production
The build process:
- Bundles all JavaScript and CSS
- Optimizes images and assets
- Minifies code for smaller file sizes
- Generates source maps for debugging
- Creates a static site in the
dist/folder
Deployment Platforms
Vercel (Recommended)
Vercel provides zero-configuration deployment for Vite projects.Netlify
Netlify is another excellent platform for deploying Vite apps.Netlify Configuration
Create anetlify.toml file in your project root:
netlify.toml
The redirects section ensures React Router works correctly by redirecting all routes to
index.html.Other Platforms
GitHub Pages
Free hosting for public repositories. Requires additional configuration for SPAs.
Cloudflare Pages
Fast global CDN with unlimited bandwidth on the free tier.
AWS S3 + CloudFront
Scalable cloud hosting with full control and customization.
Firebase Hosting
Google’s hosting platform with easy integration with Firebase services.
Environment Variables
Music Store uses Supabase for the backend, which requires environment variables.Local Development
Create a.env file in the project root:
.env
Production Environment Variables
- Vercel
- Netlify
- CLI
- Go to your project settings on Vercel
- Navigate to Environment Variables
- Add your variables:
VITE_SUPABASE_URLVITE_SUPABASE_ANON_KEY
- Redeploy your project
Security:
- Never commit
.envfiles to Git - Add
.envto.gitignore - Use different keys for development and production
- Rotate keys if they’re exposed
Build Optimization
Asset Optimization
Vite automatically optimizes assets during build:- JavaScript: Minified and tree-shaken
- CSS: Minified and extracted
- Images: Optimized and hashed for caching
- Fonts: Inlined or optimized
Code Splitting
Vite automatically code-splits your app. To manually split:Analyze Bundle Size
Install the Rollup Visualizer plugin:vite.config.js:
vite.config.js
Performance Tips
Lazy Load Routes
Use React.lazy() to split routes into separate chunks
Optimize Images
Use modern formats (WebP, AVIF) and responsive images
Minimize Dependencies
Audit and remove unused npm packages
Enable Compression
Use gzip or brotli compression on your server
Deployment Checklist
Continuous Deployment
GitHub Actions with Vercel
Create.github/workflows/deploy.yml:
.github/workflows/deploy.yml
Troubleshooting
Common Issues
404 errors on refresh
404 errors on refresh
Problem: Getting 404 errors when refreshing routes other than home.Solution: Configure your hosting platform to redirect all routes to For Vercel, create
index.html.For Netlify, add this to netlify.toml:vercel.json:Environment variables not working
Environment variables not working
Problem: Environment variables are undefined in production.Solution:
- Ensure variables are prefixed with
VITE_ - Add variables to your hosting platform’s environment settings
- Redeploy after adding environment variables
Large bundle size
Large bundle size
Problem: Build is too large and loads slowly.Solution:
- Lazy load routes and heavy components
- Analyze bundle with rollup-plugin-visualizer
- Remove unused dependencies
- Use dynamic imports for large libraries
Assets not loading
Assets not loading
Problem: Images or fonts not loading after deployment.Solution:
- Use relative paths or import assets
- Ensure assets are in the
public/folder or imported - Check the build output in
dist/folder
Post-Deployment
Monitor Performance
Use Lighthouse and analytics to track site performance
Set Up Error Tracking
Integrate Sentry or similar for error monitoring
Enable Analytics
Add Google Analytics or Plausible for user insights
Regular Updates
Keep dependencies updated for security and performance
