Skip to content

NodeJS support #20824

@crubier

Description

@crubier

Is your feature request related to a problem? Please describe.

Running Three on Node is a massive pain

Making packages that are based on Three and meant to run on Web, NodeJS, and React Native is a massive pain.

With a colleague we have plan to make it easier by providing a node specific build, just like there is a jsm specific build.

Describe the solution you'd like

The plan is to do this:

  • Create node compatible versions of at least:
    • src/loaders/ImageLoader.js => src/loaders/ImageLoader.node.js
    • src/loaders/FileLoader.js => src/loaders/FileLoader.node.js
    • examples/js/loaders/GltfLoader.js => examples/js/loaders/GltfLoader.node.js
    • examples/js/loaders/GltfExporter.js => examples/js/loaders/GltfExporter.node.js
  • Edit the rollup config of utils/build/rollup.config.js :
    • Add an alias plugin to manage the two first changed packages above
    • Add a fourth bundle of three with output: "three.node.js" including the alias plugin
  • Edit the utils/build/modularize.js:
    • Add another dst folder additionally to the jsm one
    • Add a field called nodePath in files items pointing to the node version of the file if relevant
    • Modify the convert function to output something similar to the jsm version with: if ( keys ) imports.push( 'import {${keys}\n} from "${pathPrefix}../../build/three.node.js";' );

Would you accept such a PR back into the main three.js repo / package ?

Describe alternatives you've considered

We use a custom sh***y fork of an old version three in our repo and it is messy, we'd like to go for a cleaner version that is now possible thanks to the cleanup of the three codebase using ES modules.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions