Overview
The MLM CMMS application uses Vite as its build tool to create optimized production bundles. This guide covers the complete build process, optimization strategies, and deployment configuration.Build Configuration
Vite Configuration
The application’s build is configured invite.config.ts:
- React Fast Refresh for development
- TailwindCSS v4 integration via Vite plugin
- Automatic version injection from
package.json
Package.json Scripts
The application provides multiple build scripts:Build Process
Development Build
For local development with hot module replacement:http://localhost:5173 with:
- Fast HMR (Hot Module Replacement)
- Source maps for debugging
- Unminified code
QA/Staging Build
For QA and staging environments:Run QA Build
- Uses
.env.qafor environment variables - Creates optimized build in
dist/ - Applies production optimizations
Production Build
For production deployment:Build Output
After building, thedist/ directory contains:
Asset Optimization
Vite automatically applies:Code Splitting
Automatically splits vendor dependencies and route-based chunks for faster initial load.
Minification
Minifies JavaScript and CSS using esbuild for maximum compression.
Tree Shaking
Removes unused code from the final bundle.
Asset Hashing
Adds content hashes to filenames for optimal cache busting.
HTTP Headers Configuration
Thepublic/_headers file configures security and caching headers:
These headers are automatically applied by platforms like Netlify and Vercel that support
_headers files.Security Headers Explained
- X-Content-Type-Options: nosniff - Prevents MIME type sniffing
- Referrer-Policy - Controls referrer information sent with requests
- X-Frame-Options: SAMEORIGIN - Prevents clickjacking attacks
- Permissions-Policy - Restricts browser features for security
Caching Strategy
- Service Worker & Manifests: No caching (always fresh)
- HTML Files: No caching (ensures latest app shell)
- Hashed Assets: Immutable long-term caching (1 year)
SPA Routing Configuration
Thepublic/_redirects file enables client-side routing:
- Redirects all routes to
index.html - Maintains the URL for React Router
- Returns HTTP 200 status (not 404)
- Enables proper SPA navigation
Deployment Platforms
Netlify Deployment
Configure Build Settings
- Build command:
npm run build:prod - Publish directory:
dist - Node version: 18 or higher
Set Environment Variables
Add environment variables in Netlify dashboard:
VITE_SUPABASE_URLVITE_SUPABASE_ANON_KEYVITE_WEB_PUSH_PUBLIC_KEY
Vercel Deployment
Static Hosting (Generic)
For any static hosting provider:- Build Locally
- Upload to Server
- Configure Server
PWA Configuration
The application includes Progressive Web App features:Service Worker
public/sw.js provides:
- Offline support
- Asset caching strategies
- Background sync for push notifications
- Cache-first strategy for static assets
Web App Manifest
public/manifest.webmanifest defines:
- App name and icons
- Display mode (standalone)
- Theme colors
- Start URL
PWA features require HTTPS in production. Push notifications will not work over HTTP.
Build Optimization Tips
Analyze Bundle Size
Add the rollup-plugin-visualizer:Update
vite.config.ts to generate bundle analysis.Optimize Images
- Use WebP format for images
- Compress images before adding to repository
- Use responsive images with srcset
Release Management
The project includes semantic versioning scripts:- Runs
npm run lint(via preversion) - Runs
npm run build(via preversion) - Increments version in
package.json - Creates a git commit with message “chore(release): x.x.x”
- Creates a git tag
- Pushes commit and tags to remote (via postversion)
Troubleshooting
Build Fails with TypeScript Errors
Environment Variables Not Applied
- Ensure variable names are prefixed with
VITE_ - Restart the build process after changing
.envfiles - Verify the correct
.envfile is being used for your build mode
Assets Not Loading After Deployment
- Check that the base URL is correct in
vite.config.ts - Verify all files in
dist/assets/were uploaded - Check browser console for CORS errors
- Ensure Content-Type headers are correct
Service Worker Not Updating
Next Steps
Supabase Configuration
Complete the deployment by configuring Edge Functions, Storage, and Realtime in Supabase.