vehicle-generator/vite.config.ts
CRT d8f3a6e3df Vehicle Generator 0.1.0 (alpha)
Procedural, game-ready vehicles for three.js: 13 body styles, blending, seeded
random vehicles, three LODs, colliders, 13 parametric mods, paint and livery,
a rig that drives, and GLB export that a game can load and drive. Ships with a
studio (browser or Tauri desktop app) and a Play mode.
2026-10-11 00:22:23 +00:00

49 lines
2.1 KiB
TypeScript

import { defineConfig, type Plugin } from 'vite'
/**
* Development only: errors in the page (the Tauri window has no open devtools)
* are sent over the HMR socket and printed in the dev server's terminal.
*/
function pageErrors(): Plugin {
return {
name: 'vehicle-generator:page-errors',
apply: 'serve',
configureServer(server) {
// A dev-only trigger for the style showcase (src/app/showcase.ts), for recordings.
server.middlewares.use('/__vehicle-generator/showcase', (req, res) => {
const interval = Number(new URL(req.url ?? '', 'http://x').searchParams.get('interval')) || 300
server.ws.send({ type: 'custom', event: 'vehicle-generator:showcase', data: { interval } })
res.end(`showcase every ${interval} ms\n`)
})
server.ws.on('vehicle-generator:error', (data: { kind: string; message: string; stack?: string; where?: string }) => {
console.error(`\x1b[31m[page ${data.kind}]\x1b[0m ${data.message}${data.where ? ` (${data.where})` : ''}${data.stack ? `\n${data.stack}` : ''}`)
})
},
}
}
export default defineConfig({
plugins: [pageErrors()],
resolve: {
alias: [
// `three` and `three/webgpu` are separate bundles, each with its own copy
// of the core classes. The generator imports plain `three` so it stays
// usable from WebGL-only projects; the viewer runs WebGPURenderer, so here
// the two are pointed at one copy. A regex, because a string alias would
// prefix-match and break `three/addons/...`.
{ find: /^three$/, replacement: 'three/webgpu' },
],
},
// The desktop shell (src-tauri) loads the dev server from this exact port.
clearScreen: false,
// Cargo writes and locks binaries under src-tauri/target while the dev server
// is up; watching them crashes the watcher on Windows (EBUSY).
server: { port: 5173, strictPort: true, watch: { ignored: ['**/src-tauri/**'] } },
build: {
target: 'esnext',
outDir: 'dist',
emptyOutDir: true,
// three/webgpu is one large module; splitting it buys nothing for a single-page tool.
chunkSizeWarningLimit: 2500,
},
})