Looking for a way to import modules dynamically

oh wow, i did not know it could do that. just saw it in the documentation. rollup is pretty amazing.

ok, let’s make one :sweat_smile:

mkdir 1
cd 1
npm i three
npm i rollup
npm i @rollup/plugin-node-resolve

make a file 3.js with this:

import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

window.THREE = THREE;
window.THREE.OrbitControls = OrbitControls;

npx rollup -i 3.js -o 3.iife.js -f iife -p node-resolve

enjoy.

edit: turns out there is this line

var THREE = /*#__PURE__*/Object.freeze({

so window.THREE.OrbitControls = OrbitControls; will fail - just do window.OrbitControls = OrbitControls; instead :pensive:

@makc3d lol yup