-
-
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
update build setup to the simplest migration to WebGPU #29827
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
e49ce84
to
b4266d8
Compare
|
Just one data point but I like this a lot. It would make my life easier. |
I think the difficulty in this approach is going to be that top-level await (TLA) is not widely supported across environments and build tools. We use TLA for the WebGPU builds (and can afford to use newer syntax like TLA there), but with this change the 'stable' While I haven't done the deep dive on which exact environments and build tools will break on TLA (this would be welcome information!), my feeling is that #29404 will be the safer path, and should not require build configuration changes in any modern build setup (with support for There is also the consideration that the 'default' bundle will be much larger for CDN-based applications, containing both WebGL and WebGPU builds, and they'd want to switch to backend-specific imports instead. But I'm not so worried about that part. |
@donmccurdy Can you please provide a simple reproduction? I posted the following test repo that proves there are no TLAs in current Threejs source code: https://github.com/trusktr/esbuild-three-test/tree/1eb16cb2a8775937f83cfe75454f868d2c8eff3c Specifically, the comment on this line explains: |
b4266d8
to
b5af57d
Compare
The difference between
and
To make this tree shakeable by any build tool (not only Three's build setup, and even if importing both WebGPURenderer and BasicNodeLibrary from this.library = null; and the user would be required to choose which library to use: import {WebGPURenderer} from 'three'
import {WhateverNodeLibrary} from 'anywhere'
const renderer = new WebGPURenderer()
renderer.library = WhateverNodeLibrary
// or
const renderer = new WebGPURenderer({library: WhateverNodeLibrary}) With this approach, |
- export both WebGL and WebGPU renderers from 'three' module so that existing projects can update without needing to configure their existing builds - provide separate optional WebGL-only and WebGPU-only entry points and builds - expose the WebGPU.Nodes builds in package exports for consistency with other builds - rename /src/renderers/extras/PMREMGenerator to PMREMGenerator2 to avoid confusion with src/extras/PMREMGenerator - ensure that all entry points have the same lines, but commented or uncommented, for sanity checking
b5af57d
to
23b905e
Compare
It does require at the very least an |
Closing in favour of #29404 |
I don't think this seems correct for build tools supporting import { Scene } from 'three';
import { Scene as Scene2, WebGPURenderer } from 'three/webgpu';
console.log(Scene === Scene2); // → true Tested with Vite v5.4, and the three.js build from #29404. Importantly, the test above fails on the current r170 release, without Cody's changes, and prints the troublesome "multiple versions of three.js" warning.
Hm, I do find that a bit confusing. If that's a major difference in tree-shaking size then I wouldn't be opposed to alternatives, but I think that should probably be considered downstream of the decisions about build artifacts.
Ah, thanks! Very possibly this is not a problem any more, I had missed #29218. I do vote to continue with #29404, as @mrdoob suggests, I think that approach balances various concerns. |
Related issue:
Description
Updates the build setup
Three.WebGL.js
entry point (and build) that allows people who really need the WebGL-only entry point (or build) to choose that option, while not requiring everyone else to do more workexports
for consistency with other buildsthree/tsl
path alone, which is redundant, but it could easily be deleted.The new mental model for anyone importing would be
three
for the whole lib (same as before),three/*
for slimmer versions.In my opinion this is a consistent way to do it, besides also being easier to consume.
This solution makes migration to WebGPU the simplest because it requires no build configuration updates in downstream projects. All they need to do is update the
three
version number, and then import newWebGPURenderer
and related APIs (unless there's something I overlooked, if so please let me know).This contribution is funded by my time :)