Skip to main content

Overview

Gridfinity Builder uses Vite to create optimized production builds with TypeScript compilation, code splitting, tree-shaking, and minification.

Build Process

1

Run TypeScript compiler

First, TypeScript compiles your code and checks for type errors:
This step:
  • Type-checks all .ts and .tsx files
  • Generates declaration files if needed
  • Validates TypeScript configuration
2

Build with Vite

Create the production bundle:
The build script runs:
3

Verify the build

Check the build output in the dist/ directory:
You should see:
  • index.html - Entry HTML file
  • assets/ - Bundled JS, CSS, and chunks
  • WASM files (manifold-3d)
  • PWA assets (service worker, manifest)

Build Output

The production build creates an optimized dist/ 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:
This starts a local static file server:
The preview server uses port 4173 by default, different from the dev server (5173).

Build Configuration

The build is configured in vite.config.ts:

Key Configuration

Deployment

Static Hosting

The dist/ folder can be deployed to any static hosting service:

Server Requirements

Ensure your server is configured correctly for Single Page Applications (SPAs).
Required configurations:
  1. MIME types - Serve .wasm files with correct MIME type:
  2. Fallback routing - All routes should serve index.html (for client-side routing): Nginx:
    Apache (.htaccess):
  3. HTTPS - Required for PWA installation and service workers
  4. CORS headers - If serving WASM from CDN:

Environment Variables

Vite exposes environment variables prefixed with VITE_:
Access in code:

Build Optimization Tips

Analyze bundle:
Add to vite.config.ts:
Run npm run build to generate an interactive bundle analysis.
Add Brotli/Gzip compression:
Separate third-party libraries for better caching:
The Manifold WASM module is large (~5MB). Ensure:
  1. Lazy load - Only load when needed (already implemented via Web Worker)
  2. Cache - Service worker caches WASM file
  3. CDN - Serve from CDN with Brotli compression
  4. Preload - Add to index.html:

Troubleshooting

TypeScript compilation must succeed before Vite builds:
Ensure your server:
  1. Serves .wasm with MIME type application/wasm
  2. Has correct CORS headers if WASM is on a different origin
  3. Uses HTTPS (required for SharedArrayBuffer)
Test locally:
Clear the service worker cache:
In browser DevTools:
  1. Application → Service Workers → Unregister
  2. Application → Storage → Clear site data
  3. Hard refresh (Ctrl+Shift+R)
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