Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

1.2 KB
Raw Blame
// bun reads @react-three/fiber's `main` (its CommonJS build), which requires three's CommonJS build: a second three
// beside the ES one, whose classes R3F's checks (instanceof THREE.Color) then don't know. raea's bundler takes R3F's
// `module` (ES) build, as Vite does; here the CommonJS file is loaded as the ES build's source, so the tests do too.
import { plugin } from "bun";
import { readFileSync } from "node:fs";

plugin({
  name: "r3f-es",
  setup(b) {
    b.onLoad({ filter: /@react-three\/fiber\/dist\/react-three-fiber\.cjs\.js$/ }, (a) => ({
      contents: readFileSync(a.path.replace(/\.cjs\.js$/, ".esm.js"), "utf8"),
      loader: "js",
    }));
    // drei and three-stdlib the same: their CommonJS builds require three's (OrbitControls' instanceof
    // PerspectiveCamera failed, so the wheel's dolly was off)
    b.onLoad({ filter: /@react-three\/drei\/index\.cjs\.js$/ }, (a) => ({
      contents: readFileSync(a.path.replace(/\.cjs\.js$/, ".js"), "utf8"),
      loader: "js",
    }));
    b.onLoad({ filter: /three-stdlib\/.+\.cjs$/ }, (a) => ({
      contents: readFileSync(a.path.replace(/\.cjs$/, ".js"), "utf8"),
      loader: "js",
    }));
  },
});