-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: Update import instructions in readme. #21113
Conversation
I am not ready to concede defeat on this fight 😅 Here's my proposal: #21128 |
clears throat keep up the good work @mrdoob and co. ya'll are doing super. @donmccurdy perhaps splitting/sectioning the readme? a browser section followed by a node.js section? |
Giving #21128 a try. I'll reconsider this one if I see that things don't improve... |
I do like #21128, but my remaining concern is that if you start from this line... import * as THREE from './js/three.module.js'; ... and put import * as THREE from './$PATH_TO_THREE/build/three.module.js'; Then at least (1) relative imports from |
Yes, I understand. The problem is, if we do So... the way I see it, we have 2 options:
|
Please not... |
Why not? 🤔 |
I remember we discussed this topic in #20455 and it become apparent that the development community seems divided about this issue. I still do think that working with global scripts is a bad thing, sorry. And we should stop doing it as soon as possible. My thoughts: If you just need the core of But remember the more complex examples like the post-processing ones. The imports looked awful in the early days. Because components like At the time when Nowadays we have a module system in JavaScript and build systems like rollup. I believe it's more future-proof and robust to guide users to those technologies. The most important thing is that manually downloading a library and copy it to a project directory is a No-Go in the module space. Unfortunately, I'm not sure how import maps will change this fact. AFAIK, they allow the usage of bare import specifiers and the configuration of the module resolution in the browser. However, users still have to define the mapping of bare import names to a relative or absolute URL. So it won't be the same like with global scripts. Hence, I think it's best when users retrieve modules with a dependency manager or by using CDN URLs to a single host. I would use this pattern in the README file for now: import * as THREE from 'https://unpkg.com/three/build/three.module.js'; In this way, the code matches to the respective live example. |
Import maps allows using modules in a similar way to global scripts. For example: <script type="importmap">
{
"imports": {
"three": "./js/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OBJLoader } from './js/OBJLoader.js';
import { OrbitControls } from './js/OrbitControls.js';
console.log( THREE, OBJLoader, OrbitControls );
</script> With import maps we can change The only path the developer would have to specify is the path for |
But what if the user downloads Besides, what happens if you include |
Sidenote: Maybe it's time to think about a
|
Correction... it doesn't. It's only the first lesson. They teach webpack. |
This came up some times over the years but not enough times to worry me.
I know this is just one example but I was hoping to eventually deprecate The thing is... An important goal of mine was to make all this as approachable as possible for newbies but this is becoming harder and harder because experienced developers are building more a more tools that make newcomers learning curve stepper and stepper. The first bump in the road was when it was no longer possible to use the library without running a web server. This period lasted around 5 years or so, and during that time Then commonjs became a thing, and we had to tweak a bunch of files so experienced developers could use the library on their projects. This period didn't last long. Then es6 modules became a thing, we adopted them but now what's happening is that experienced devs are so used to the npm workflow that they would never think of copying files from On top of that, es6 modules in the browser without importmaps is half baked. We realised this when we updated the examples to use modules. In order to make them work we had to do the Now we have example modules that are a hack for both, experienced devs and newbies. I wish browsers had just waited for importmaps before adding es6 modules support. In retrospect, we adopted es6 modules in examples way too early. At this point I'm starting to wonder if isn't just easier to:
I've been trying to think a solution for this for a while, but I'm not smart enough.
|
If we bet on importmaps and adopt the polyfill then the code would look like this: <script defer src="./js/es-module-shims.js"></script>
<script type="importmap-shim">
{
"imports": {
"three": "./js/three.module.js"
}
}
</script>
<script type="module-shim">
import * as THREE from 'three';
import { OBJLoader } from '../addons/OBJLoader.js';
import { OrbitControls } from '../addons/OrbitControls.js';
console.log( THREE, OBJLoader, OrbitControls );
</script> Or... We can revert to use global scripts in examples, and wait until importmaps are widely adopted. |
If only those two options would be available, I vote for the second one (import maps). But yeah, this is a complicated topic and I feel I need more time to think about it in order to suggest a solution that is in some sense a good compromise for everybody. |
Yup, but you could also say that was a good thing. Place your bets everyone. Sounding like there's no simple good option. |
AFAICS, we all agree to generate Especially since there is already a PR trying to implement this feature (#20527). And solving this would also simplify the contribution and development process (see https://discourse.threejs.org/t/how-to-develop-in-examples-jsm-es6-vs-es5/22841). |
I was watching this video and found it "funny" that this actually works... Because the modules are trying to resolve this:
😬 |
The import instructions from README.md are shown on the npm package homepage (https://www.npmjs.com/package/three) and may create confusion about how to import the library. I think it's best to advise imports from the
three
namespace — any workflow involving copying files into project folders will be messy, running into issues like duplicate imports.