2018-package-three-webpack-plugin icon indicating copy to clipboard operation
2018-package-three-webpack-plugin copied to clipboard

Files with multiple exports

Open cecilemuller opened this issue 6 years ago • 7 comments

Several files define multiple classes per file (EffectComposer, MaskPass, etc).

Some don't even define in the THREE namespace, or aren't intended to be importable scripts:

Cloth.js
Detector.js
GPUComputationRenderer.js
ImprovedNoise.js
MD2Character.js
MD2CharacterComplex.js
PRNG.js
RollerCoaster.js
SimplexNoise.js
crossfade/gui.js
crossfade/scenes.js
crossfade/transition.js
geometries/hilbert2D.js
geometries/hilbert3D.js
libs/ammo.js
libs/dat.gui.min.js
libs/draco/draco_decoder.js
libs/draco/draco_wasm_wrapper.js
libs/draco/gltf/draco_decoder.js
libs/draco/gltf/draco_encoder.js
libs/draco/gltf/draco_wasm_wrapper.js
libs/gunzip.min.js
libs/inflate.min.js
libs/jszip.min.js
libs/mmdparser.min.js
libs/msgpack-js.js
libs/o3dgc.js
libs/opentype.min.js
libs/stats.min.js
libs/system.min.js
libs/timeliner_gui.min.js
libs/tween.min.js
lights/RectAreaLightUniformsLib.js
lines/Line2.js
lines/LineSegments2.js
lines/WireframeGeometry2.js
loaders/MD2Loader.js
loaders/OBJLoader2.js
loaders/UTF8Loader.js
loaders/ctm/CTMWorker.js
loaders/ctm/ctm.js
loaders/ctm/lzma.js
loaders/sea3d/SEA3D.js
loaders/sea3d/SEA3DDeflate.js
loaders/sea3d/SEA3DLZMA.js
loaders/sea3d/SEA3DLegacy.js
loaders/sea3d/SEA3DLoader.js
loaders/sea3d/o3dgc/SEA3DGC.js
loaders/sea3d/physics/SEA3DAmmo.js
loaders/sea3d/physics/SEA3DAmmoLoader.js
loaders/sea3d/physics/SEA3DRigidBody.js
nodes/inputs/Matrix3Node.js
nodes/inputs/Matrix4Node.js
nodes/inputs/Vector2Node.js
nodes/inputs/Vector3Node.js
nodes/inputs/Vector4Node.js
nodes/math/Math1Node.js
nodes/math/Math2Node.js
nodes/math/Math3Node.js
renderers/CSS2DRenderer.js
renderers/CSS3DRenderer.js
shaders/OceanShaders.js
vr/WebVR.js
workers/OffscreenCanvas.js

I'm analyzing the files to extract which files define what, then they can be added to customExports, with matching test fixtures.

cecilemuller avatar Jun 26 '18 19:06 cecilemuller

The first pass used a few regex to have a quick overview of the styles of exportable classes; the second pass is now parsing to AST to be most accurate, and I already extracted exports for most files. There are about 20 remaining, mostly from exotic IIFE-style syntaxes.

While I could do those 20 manually, I'd rather automate it so the list of exports can be easily updated on new three.js releases.

While this plugin started as just a easier way to use the "imports-loader + exports-loader" trick from the neverending "Convert examples to modules" issue thread, it's obvious now that the trick wasn't working for a lot of files anyway, so making this plugin was definitely the right decision 😃 (of course, I'd still rather the examples in the three.js repository were converted to ES Modules directly).

cecilemuller avatar Jun 27 '18 18:06 cecilemuller

Using Proxy objects and Puppeteer, I was able to also aggregate which files depends on classes from THREE and SEA3D namespaces, so given the large number of changes, even if it's not a breaking change, I'll make the next update a major version number (3.0.0 instead of 2.1.0).

Also, as much as I wanted to make the plugin independent from the three.js versions, it will have to have definitions of imports/exports per version (given dependencies might change between three.js releases), so the plugin will read the version of the "three" package that the user uses to find the matching definitions (and default to the latest version if it doesn't yet have them, in case the user updated to a newer version of three before I had time to publish an updated with an additional list for it).

Even if examples never get converted to modules in the three.js repo, I wish they at least listed their dependencies in a comment, then the plugin wouldn't need a list for every release, it would get the updated list from three.js itself.

cecilemuller avatar Jul 02 '18 14:07 cecilemuller

Closed just now the 2.1.0 branch because it doesn't have all the changes I'm doing in parallel with the AST parser (plus the new version will be 3.0.0).

cecilemuller avatar Jul 11 '18 06:07 cecilemuller

Great job with this plugin man!

marcofugaro avatar Aug 16 '18 22:08 marcofugaro

Thanks 😃 Ah, I'm hoping to be able to work on the update next week or the week after, it's just that customer projects are taking all my time right now.

cecilemuller avatar Aug 17 '18 17:08 cecilemuller

Sure thing man! Another weird thing I noticed is that some files require other files, for example the OBJLoader2 is requiring the LoaderSupport, from this line, how would you handle this case?

marcofugaro avatar Aug 17 '18 21:08 marcofugaro

Files requiring other files is exactly one of the things I want to work on in the update because there are a few files which implicitly depend on other files, so the plugin will have to add additional imports in those.

So I don't have a quickhack solution for now (other then adding the files in the webpack entry like a polyfill instead of using this plugin, in which case you'd access the threejs extensions from window.THREE instead of using an import).

cecilemuller avatar Aug 17 '18 23:08 cecilemuller