import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; // Vite config for Rublox Player. // // - port 5173 is fixed (player code and external links assume it) // - outDir 'build' (deployed under nginx /var/www/rublox-player/build/) // - manualChunks split babylon/colyseus into separate chunks // (engine ~46k lines, single-bundle build is >5 MB; browsers parse longer) // - define for process.env.NODE_ENV — shim for engine code that used the // CRA-provided global // - dev proxy targets staging by default; override via VITE_API_PROXY_TARGET // in .env.development.local to point at your own backend. export default defineConfig(({ mode }) => { // Load env so we can use VITE_API_PROXY_TARGET in proxy config. const env = loadEnv(mode, process.cwd(), ''); const PROXY_TARGET = env.VITE_API_PROXY_TARGET || 'https://dev-api.rublox.pro'; // All backend prefixes the player talks to. // Each entry creates a Vite proxy: /api-X/* → ${PROXY_TARGET}/api-X/* const proxyPrefixes = ['/api-user', '/api-storys', '/api-game']; const proxy = Object.fromEntries( proxyPrefixes.map((p) => [ p, { target: PROXY_TARGET, changeOrigin: true, secure: true, ws: true }, ]) ); return { plugins: [react()], server: { // Bind IPv4 explicitly — Vite defaults to [::1] on Windows, which // breaks IPv4 localhost (ECONNREFUSED from curl / browser). host: '127.0.0.1', port: 5173, strictPort: true, proxy, }, build: { outDir: 'build', sourcemap: false, rollupOptions: { output: { manualChunks: { babylon: ['@babylonjs/core', '@babylonjs/loaders'], colyseus: ['colyseus.js'], }, }, }, }, define: { 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'), }, }; });