Skip to content

Repository files navigation

React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Three.js stack (src/three)

  • React mounts a container div; Experience is the app entry (singleton for dev HMR).
  • Engine owns WebGL: scene, camera, renderer, Time, Viewport, controls, Loader, etc. It takes Config (camera, antialias, maxDevicePixelRatio, #debug hash).
  • Debug: open the app with #debug in 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/ as SceneModule implementations (e.g. DemoScene). Register new modules in Experience.
  • Environment maps: Loader no longer mutates the scene. After loadHDR / loadEXR / cube loads, call applyEnvironmentToScene(scene, texture, options) (re-exported from Loader).
  • Singleton / HMR: Experience.getInstance(container) keeps one instance; Vite stores it on import.meta.hot.data so edits to Experience.ts can 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 verify destroy() / module teardown disposes listeners and GPU resources.

More detail: src/three/README.md.

Currently, two official plugins are available:

React Compiler

The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.

Expanding the ESLint configuration

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-noise
npm i -D @types/three @tweakpane/core vite-plugin-glsl @types/mersennetwister

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages