Nothing serious here, just looking to satisfy my curiosity.
The background of this question is similar to this one, but a little different, because it targets using a browser’s built-in module support, rather than using a bundler or a CDN like unpkg.com. There is also a little confusion between what is in GitHub vs. what is in npm
, which I’ll detail in a moment.
First, here’s the basics of the environment:
<!-- path = /index.html -->
<script src="main.js" type="module"></script>
// path = /main.js
import { OrbitControls } from './node_modules/three/examples/jsm/controls/OrbitControls.js'
This fails in the browser because the npm
version of three.js
(0.130.1
) imports its dependencies from 'three';
. The browser can’t resolve ‘three’ to a path, so it fails.
Most of my confusion came when I was trying to reference the code for answering a SO question. In GitHub, the dependencies import is: from '../../../build/three.module.js';
(and this is up to the most recent version). Using this fixes the pathing for the browser.
Now that I’m done pointing out the obvious, I guess my questions are:
Is the npm
version of three.js
specifically built with the assumption that you’ll be using it with a bundler? I guess that’s fine, if true, because you’re in the environment, so the assumption could be made that a bundler will be involved. But using es modules (not to be confused with node
/npm
modules) is becoming better supported, and it’s easier to use a manager like npm
to keep dependencies up-to-date, rather than manually downloading each one from GitHub.
Is any consideration made for browser-based module support (beyond the core libraries*), or is the “roadmap” simply that three.js
is always intended to be used with a bundler?
* making this distinction, because the examples are, after all, only meant to be examples.
P.S. I also noticed the npm
version is 0.130.1
, but there’s no associated tag in GitHub. Are patches not tracked on GH?