Now we’ve switched to using “import” to load libraries and components.
Put this script tag in your HTML BEFORE any other scripts:
<script type="importmap">
{
"imports": {
"three": "https://threejs.org/build/three.module.js",
"three/addons/": "https://threejs.org/examples/jsm/"
}
}</script>
Load your own script after like:
<script type="module" src="./YourMainScript.js"></script>
(notice the type = ‘module’ means you can now use “import” in your scripts)
Then in YourMainScript.js:
use:
import *as THREE from "three"
import {OrbitControls} from "three/addons/controls/OrbitControls.js"
To load the different things.
With this setup, now you can change where you are pulling threejs and its components, just by changing the importmap. It’s a more flexible mechanism and keeps most of the code interaction in the .js files instead of woven through the html.