Deployment
How to build and deploy RayTracer Studio for production.
Build for Production
1. Build WASM Module
First, compile the C++ code to WebAssembly:
npm run build:wasm
This creates:
src/wasm/raytracer.js- JavaScript loadersrc/wasm/raytracer.wasm- WebAssembly binary
2. Build React App
npm run build
This creates optimized production files in dist/.
Deployment Options
Vercel
The recommended deployment platform:
-
Push to GitHub
git add .
git commit -m "Production build"
git push -
Connect to Vercel
- Go to vercel.com
- Import your GitHub repository
- Vercel auto-detects Vite
-
Configure (already in
vercel.json):{
"buildCommand": "npm run build",
"outputDirectory": "dist",
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" },
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" }
]
}
]
}
GitHub Pages
-
Install gh-pages
npm install --save-dev gh-pages -
Add deploy script to
package.json:{
"scripts": {
"deploy": "npm run build && gh-pages -d dist"
}
} -
Update
vite.config.js:export default defineConfig({
base: '/rayTracing/', // Your repo name
// ...
}); -
Deploy
npm run deploy
Netlify
-
Create
netlify.toml:[build]
publish = "dist"
command = "npm run build"
[[headers]]
for = "/*"
[headers.values]
Cross-Origin-Opener-Policy = "same-origin"
Cross-Origin-Embedder-Policy = "require-corp" -
Connect and deploy via Netlify dashboard
Self-Hosted
-
Build the app
npm run build -
Serve the
dist/folder with any static file server:npx serve distOr with nginx:
server {
listen 80;
root /var/www/raytracer/dist;
add_header Cross-Origin-Opener-Policy "same-origin";
add_header Cross-Origin-Embedder-Policy "require-corp";
location / {
try_files $uri $uri/ /index.html;
}
}
Required Headers
WebAssembly with SharedArrayBuffer requires these headers:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Without these headers, certain WASM features may not work.
Pre-building WASM
Since Vercel/Netlify don't have Emscripten, you must:
- Build WASM locally:
npm run build:wasm - Commit the generated files:
git add src/wasm/raytracer.js src/wasm/raytracer.wasm
git commit -m "Add compiled WASM" - Push and deploy
The .gitignore should NOT ignore src/wasm/ for deployment.
Documentation Deployment
Build Documentation
cd docs
npm install
npm run build
Deploy to GitHub Pages
cd docs
npm run deploy
This publishes to https://username.github.io/repo/.
Deploy to Vercel
Create a separate Vercel project for the docs/ folder, or use a monorepo setup.
Environment Variables
No environment variables are required. All configuration is in the code.
Performance Tips for Production
- Use higher resolution in production (768 or 1024)
- Enable compression on your server (gzip/brotli)
- Set cache headers for
.wasmfiles (they don't change often)
location ~* \.wasm$ {
add_header Cache-Control "public, max-age=31536000";
}