Overview
Gridfinity Builder uses Vite to create optimized production builds with TypeScript compilation, code splitting, tree-shaking, and minification.Build Process
Run TypeScript compiler
First, TypeScript compiles your code and checks for type errors:This step:
- Type-checks all
.tsand.tsxfiles - Generates declaration files if needed
- Validates TypeScript configuration
Build Output
The production build creates an optimizeddist/ directory:
Optimization Features
- Code splitting - Lazy-loaded routes and components
- Tree shaking - Unused code eliminated
- Minification - JavaScript and CSS compressed
- Asset hashing - Cache-busting file names
- WASM optimization - Manifold 3D module bundled efficiently
- PWA caching - Service worker for offline support
Preview Production Build
Test the production build locally before deployment:The preview server uses port 4173 by default, different from the dev server (5173).
Build Configuration
The build is configured invite.config.ts:
Key Configuration
| Option | Purpose |
|---|---|
@vitejs/plugin-react | Fast Refresh, JSX transform |
@tailwindcss/vite | Tailwind CSS processing |
vite-plugin-pwa | Service worker generation |
optimizeDeps.exclude | Exclude Manifold WASM from pre-bundling |
Deployment
Static Hosting
Thedist/ folder can be deployed to any static hosting service:
Server Requirements
Required configurations:-
MIME types - Serve
.wasmfiles with correct MIME type: -
Fallback routing - All routes should serve
index.html(for client-side routing): Nginx:Apache (.htaccess): - HTTPS - Required for PWA installation and service workers
-
CORS headers - If serving WASM from CDN:
Environment Variables
Vite exposes environment variables prefixed withVITE_:
Build Optimization Tips
Reduce bundle size
Reduce bundle size
Analyze bundle:Add to Run
vite.config.ts:npm run build to generate an interactive bundle analysis.Enable compression
Enable compression
Add Brotli/Gzip compression:
Split vendor chunks
Split vendor chunks
Separate third-party libraries for better caching:
Optimize WASM loading
Optimize WASM loading
The Manifold WASM module is large (~5MB). Ensure:
- Lazy load - Only load when needed (already implemented via Web Worker)
- Cache - Service worker caches WASM file
- CDN - Serve from CDN with Brotli compression
- Preload - Add to
index.html:
Troubleshooting
Build fails with TypeScript errors
Build fails with TypeScript errors
TypeScript compilation must succeed before Vite builds:
WASM module not loading in production
WASM module not loading in production
Ensure your server:
- Serves
.wasmwith MIME typeapplication/wasm - Has correct CORS headers if WASM is on a different origin
- Uses HTTPS (required for SharedArrayBuffer)
Service worker not updating
Service worker not updating
Clear the service worker cache:In browser DevTools:
- Application → Service Workers → Unregister
- Application → Storage → Clear site data
- Hard refresh (Ctrl+Shift+R)
Large bundle size
Large bundle size
If the bundle is unexpectedly large:Common causes:
- Unused dependencies (check
package.json) - Large assets not lazy-loaded
- Duplicate dependencies (check with
npm ls <package>)
CI/CD Example
GitHub Actions
.github/workflows/deploy.yml
Next Steps
Local Setup
Set up your development environment
Docker Development
Run in a containerized environment
