-
-
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
JSM: Update rollup examples config to merge and convert files #16920
Conversation
I've done this today and found no issues related to this PR. To be more precise I've checked out 8d8ff4d (the commit before the first HTML files were migrated to modules) and then run your script. The OBJ2 examples break but only because the JSM version was temporarily different than the "normal" version in the So it seems the script produces a usable output 👍. The only thing that bothers me a bit is the fact that the linter complains about the wrong code styles in the generated files. I don't think this blocks the PR in any form but it would be nice if the files are formatted according to |
Woo! Thanks.
Yeah unfortunately I'm not sure how much control control we have over the UMD require block that gets generated: (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('three')) :
typeof define === 'function' && define.amd ? define(['exports', 'three'], factory) :
(global = global || self, factory(global.THREE = global.THREE || {}, global.THREE));
}(this, function (exports, THREE) { 'use strict';
// ...
})(); But we do have control over the indentation. I've disabled the extra indentation to make the diff easier to look at and files easier to edit but we can re-enable the added indentation so the linter doesn't spew so much by removing this line: indent: false, Once modules are in place I think it would be great to get the linter running over the examples/jsm files, as well. |
It also occurred to me that we could run |
Definitely. 👍
Just a thought, but maybe the UMD files should be minified, and omitted from the ESLint run? That would eliminate most confusion about which files to edit in PRs... |
Um, I think it's more user-friendly when the UMDs are not minified. This makes debugging easier which is an important factor. Especially when we include these files in fiddles or codepens. |
Ah, yeah the debugging point is a good one. For fiddles and codepens I think we can encourage people to use ES modules maybe, but there are lots of developers using CommonJS in build systems like Browserify still and that's fine. |
I've checked the script with Vector2Node.call( this );
this.size = new Vector2(); The script creates this:
Maybe it's better to exclude |
I can test those two files maybe tomorrow or Friday -- for
I know that nodes were originally using imports but was OBJLoader originally a module? Or hand converted from the THREE examples? Why is it different? |
This one. The old code was deleted. |
Um wait. I've had a closer loo to other files now. if ( TGALoader_js.TGALoader ) { which does not seem to be correct. It should be
Or not? When you include the UMD version of |
Oh interesting a change I made to this function may have broken it because it was definitely working before: function resolveGlobalObject( depPath ) {
if ( isLibrary( depPath ) ) {
return 'window';
} else {
return 'THREE';
}
} I'll do more testing. |
To elaborate on this a bit more this is actually correct and expected given the way that rollup converts files. The files are converted to the UMD format, which supports import { TGALoader } from './TGALoader.js';
import { /* ... */ } from '../../../builds/three.module.js'; Rollup passes each of these imports in as a separate object so when using require it calls the ColladaLoader definition function with the following arguments (the first argument being the exported object that ColladaLoader will be added on to): // UMD
(exports, require('three'), require('..\TGALoader.js')) When loading in a global script context, though, we've specified that all the exports should be loaded from the global // global script
(global.THREE = global.THREE || {}, global.THREE, global.THREE) The function that's getting called has a signature that looks like this: function (exports, THREE, TGALoader_js) { The I know it's a bit convoluted but I hope that explanation was clear. I haven't looked into a way to share the THREE name across all imports but if it's strongly desired maybe we can take a look later, though I'd prefer to do that in a future PR. Regarding the nodes and OBJLoader2 files -- have you actually tried to use them and found them unusable? Or did the code just look unfamiliar or have unexpected variable names? |
Okay, thanks for the explanation! I think the syntax is okay like that. I just wanted to know the reasons behind it.
This one. I did not had the time to refactor the examples in order to test |
@mrdoob I think we should give this PR a try and see how it goes. We can then deprecated |
I suggest merging this at the beginning of |
@mrdoob Do we want to give this PR a try now? It's the last step to finalize the module conversion. |
Especially with all of the examples being converted to modules I think it's important that this switch be made -- I've seen a number of PRs recently that only modify the If something needs more explaining or we'd prefer to change the output of the rollup config let me know and I'll be happy to discuss / investigate! This is maybe related but are there any open PRs that are being considered that modify the |
Sorry for the delay. So... I think the strategy I'm more comfortable with by leaving Use case 1 - Improve existing file, say... GLTFLoader
Use case 2 - Add new file, say... SuperMegaControls
The idea is to update existing files in |
Hmm. Can you elaborate on what exactly makes you uncomfortable? Maybe I can find a way to convert them in a more agreeable way and simplify the config. The strategy you proposed seems like it could be a bit confusing to me, as well. If there are some examples only available as modules then new users will have to understand which examples are available where (I feel like I still see people using the old script tags but maybe that will die out soon). Contributors will also then have to understand which example file to edit and why, which won't be immediately clear. I think the bigger reason I would like the jsm files to be canonical is that development / maintenance process for examples is really poor at the moment. All the example pages now use the jsm files which means updating an example script involves
You could edit the /js files directly but then that requires manually rerunning modularize every time to actually see the changes. |
Basically, I was hoping the JS to JSM situation to be transitory. If we convert new JSM files to JS, then we're giving the signal that we support both modes and user will expect new JS files added. On top of the
That's the idea.
Yeah. We could also stop updating JS files and only update JSM files from now on. Maybe add a |
Okay. In this case, we can close the PR.
We could consider to add a npm |
Hmm okay it still doesn't feel quite right to remove the js modules completely especially given all the module import / resolution problems mentioned in some other threads, even if just to support the hacking / static example page with CDN-served libraries cases. Maybe I'm just feeling nostalgic, though :) Ideally converting the jsm files to UMD would require little to no maintenance. This PR did get complicated but I think it can be simplified if some of the other levied requirements were loosened. Would it be worth proposing a different, simpler, examples rollup config?
If this is the plan, though, is there any timeline when you might expect we can consider the |
I know what you mean. But I'm trying to make sure we don't end up in a situation were there are too many things to consider in order to advance. We can definitely keep these files for a year or so though.
I think it's better to deprecate these files and encourage people to move to ES6 Modules. A single code path it's easier to maintain than two. And, considering the recent discussions, seems like ES6 Modules are already problematic enough 😣
Yes, I think so. I think we can consider |
What do you mean by "canonical"? I think I've been using "canonical" to refer to the file a contributor should edit, and from which other files are generated. Did you mean that, or just that the JSM files should be recommended to end-users? |
^Or do we mean that contributors should edit the JSM files, and the JS files would not be updated at all moving forward? The wording, "no longer maintained or updated", in #17544 makes it sound like that is the plan... I'm not sure about that... if the point of keeping them is to give users time for the transition to ES modules, providing r108 GLTFLoader in the r115 three.js distribution seems like a confusing way to do so. |
Indeed, this will only lead to confusion. |
Indeed! I thought a bit more about this and realised the same, specially when we change APIs in core and we update the examples too. How about we continue using the existing |
@mrdoob heh I have a comment in the other issue (#17544 (comment)) but let's continue the conversation here.
I'd prefer to the get the modules canonical sooner but January isn't that far away, I suppose, if we're definitely going to remove them then. We'll have strip the warning when generating the modules, though, or the jsm files will include it, too. My preference would be to generate the js files from jsm like which would give us a bit more leeway. From #17544 (comment):
|
What specifically would happen in January 2020? |
Removal of |
Ok, if we think we'd be willing to remove
|
A few months is definitely better than a year or so :) As long as there's a light at the end of the tunnel.
I updated #17544 to include both of these. |
Related to #16917, #16688.
This PR updates the
build-examples
script to provide the ability to specify which files will be merged into a single UMD file in theexamples/js/
directory fromexamples/jsm/
. At the moment only EffectComposer and Pass are merged into a single file but it can be extended to merge other files including /nodes once #16917 is merged:Every other file is converted as-is with dependencies being considered external.
You can see the output of the conversion here and the diff here. Looking at what isn't generated it seems like
WebGL.js
,loader/ctm/CTMWorker.js
,offscreen/*
,vr/*
, andrenderers/RaytracingWorker.js
are the only other files that need to be converted to modules.I haven't had a chance to test everything yet but looking at the files it looks correct. It may be worth reverting to the pre-module versions of the example files to test that these new version work as expected.
@Mugen87 @donmccurdy