Build & Deploy
When to Use
- Starting development server or troubleshooting it
- Building for production
- Deploying to Vercel
- Configuring CORS, routes, or caching
- Managing static assets in
public/ - Fixing build errors or dependency issues
Commands
| Command | Purpose |
|---|---|
npm install |
Install dependencies |
npm run dev |
Vite dev server on port 3000 |
npm run build |
Production build → dist/ |
npm run clean |
Remove dist/ contents |
npm run deploy |
Build + vercel --prod with local config |
npm version <patch|minor|major> |
Bump version, auto-pushes via postversion |
Vite Configuration
Config: vite.config.js
- Two build targets switched via
TARGETenv var:TARGET=app(default) → multi-page app indist/(entries:index.html,features.html,embed.html,agent-home.html,agent-embed.html)TARGET=lib→ self-contained<agent-3d>web component indist-lib/(ESM + UMD, three.js bundled)
- JSX configured for vhtml:
jsxFactory: 'vhtml',jsxFragment: '"div"' - Dev server has a
vercel-rewritesmiddleware that mirrors Vercel routing for/login,/register,/dashboard,/studio,/widgets,/docs/widgets,/agent,/agent/:id,/agent/:id/embed vite-plugin-pwaemits the service worker + manifest- Static assets:
public/folder copied to build output
Vercel Deployment
Config: vercel.json
Key routes:
/assets/*— Cached 1 week (max-age=604800)/.well-known/*— Cached 1 day, serves frompublic/.well-known//robots.txt,/sitemap.xml— Served frompublic//avatars/*— Served frompublic/avatars/
Domain: three.ws
CORS Configuration
Config: cors.json
Allowed origins:
https://three.ws/and subdomainshttp://localhost:*/https://localhost:*- Specific partner domains
Static Assets
public/
├── avatars/ → Default 3D model files (GLB)
├── .well-known/ → Domain verification files
├── robots.txt → Search engine directives
└── sitemap.xml → Site map
Procedure
Local Development
npm installnpm run dev- Open
http://localhost:3000
Production Deploy
npm run build— verify no build errorsnpm run deploy— builds and deploys to Vercel- Verify at three.ws
Adding Static Assets
- Place files in
public/(copied as-is to build output) - If they need caching rules, add a route in
vercel.json - If they need CORS access, verify origins in
cors.json
Troubleshooting
- Port 3000 in use: Kill existing process or edit
package.jsondev script port - Build fails on Three.js imports: Check
threeversion inpackage.jsonmatches CDN paths inviewer.js - CORS errors: Check
cors.jsonfor allowed origins - Assets 404 after deploy: Verify route patterns in
vercel.json