This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
- React mounts a container
div;Experienceis the app entry (singleton for dev HMR). Engineowns WebGL: scene, camera, renderer,Time,Viewport, controls,Loader, etc. It takesConfig(camera, antialias,maxDevicePixelRatio,#debughash).- Debug: open the app with
#debugin the URL (e.g.http://localhost:5173/#debug) to enable Tweakpane, FPS/GPU stats, axes, and grid. Without it, those systems are not created. - Scene code lives in
world/asSceneModuleimplementations (e.g.DemoScene). Register new modules inExperience. - Environment maps:
Loaderno longer mutates the scene. AfterloadHDR/loadEXR/ cube loads, callapplyEnvironmentToScene(scene, texture, options)(re-exported fromLoader). - Singleton / HMR:
Experience.getInstance(container)keeps one instance; Vite stores it onimport.meta.hot.dataso edits toExperience.tscan rebind prototypes without losing WebGL state. Use a single canvas per app. - React StrictMode (dev): effects run mount → unmount → mount once, so the engine is created, destroyed, and created again. That is expected and helps catch leaks; not a bug.
- Performance (after changes): use Chrome Performance,
renderer.info, and verifydestroy()/ module teardown disposes listeners and GPU resources.
More detail: src/three/README.md.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Oxc
- @vitejs/plugin-react-swc uses SWC
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
// Other configs...
// Remove tseslint.configs.recommended and replace with this
tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
tseslint.configs.stylisticTypeChecked,
// Other configs...
],
languageOptions: {
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
]);You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:
// eslint.config.js
import reactX from "eslint-plugin-react-x";
import reactDom from "eslint-plugin-react-dom";
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
// Other configs...
// Enable lint rules for React
reactX.configs["recommended-typescript"],
// Enable lint rules for React DOM
reactDom.configs.recommended,
],
languageOptions: {
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
]);npm i three stats-gl stats.js tweakpane mersennetwister simplex-noisenpm i -D @types/three @tweakpane/core vite-plugin-glsl @types/mersennetwister