Hot-reload your code in the browser
site/media/lessons/playground-hmr.lesson.ts (4 steps) vgai can hot-reload your game code entirely in the browser — no Node, no Vite round-trip. The
Code Playground edits a GameComponent’s source,
transpiles it with esbuild-wasm client-side, and hot-swaps the class on the live runtime.
-
Open the Code Playground. A starter
GameComponentis already running in the real engine (a cube that spins and shifts color).
A GameComponent running live in the browser. -
Edit the component’s code. Change
update(dt)— here: spin faster, scale up, paint it green.
Edit the source right in the browser. -
Press Run — it transpiles in-browser and swaps the live game.
browser-transpile.tsruns esbuild-wasm to compile your TS to a module and rewires itsthree/@engineimports to the live singletons; the playground then re-attaches your component to the running cube (the editor’s play-mode uses the same path tohotSwapclasses in place — see the note below).
esbuild-wasm transpile + hotSwap — on the live game. -
Your change runs instantly. The cube is now green and larger — no server, no page reload.
Edit → Run → live update, fully client-side.
Recap
New functionality
- Edited a GameComponent in the browser
- Hot-swapped it into the running game with no reload
New concepts & skills
- esbuild-wasm transpiles your TS in the browser (no server)
- transpiled code shares the running three/engine singletons, so hotSwap preserves instanceof
- the same in-browser HMR powers the editor and the playground
Next lesson → SDK & storage backends