-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
adds jsnext:main field to package.json #9402
Conversation
Also, another (arguably better) option would be too add another fille in the |
I just felt it was a separate concern from the internal organisation of the codebase – agree that it'd be good to have a
That would be better – the issue with using In order to do that we'd need some additional build config (couldn't just use the targets option) because of the |
@Rich-Harris thanks for your answer
Ah, did not think about that, agree that this should be handled by Your solution sounds reasonable, I played around with it for a while but I don't think I will have time to commit to make something proper.. This PR was a bit to naive I guess ;) |
Should it be closed then? |
@mrdoob I left it open because I was considering revisiting it if I found time to, but let's close it and I can re-poen/create a new one in that case. |
In addition to the issues outlined regarding getting the rollup config right, there seems like there may be some more fundamental issues that need to be addressed. In particular
This code assumes the This code probably doesn't get on too well with tree shaking either. I noticed a similar, but different, issue was addressed in #9519 @Rich-Harris, any suggestions on how to make this work? EDIT: In general there are 18 references to |
I guess the simplest (only?) solution is that any dynamically instantiable objects need to register themselves with a builder/mapping that knows how to look them up. If we know that all files within certain directories contain a constructor matching their name and corresponding with the type string @mrdoob How do you feel about replacing the dynamic class resolution within the |
@Benjamin-Dobell good catch! Looks like Loader.js, MaterialLoader.js and ObjectLoader.js are the only files affected. A string-to-constructor/string-to-constant lookup would certainly be the most straightforward way to address this.. import { PlaneGeometry } from '../extras/geometries/PlaneGeometry.js';
import { PlaneBufferGeometry } from '../extras/geometries/PlaneBufferGeometry.js';
// ...
var geometryConstructors = {
PlaneGeometry: PlaneGeometry,
PlaneBufferGeometry: PlaneBufferGeometry,
...
}
/* later */
switch ( data.type ) {
case 'PlaneGeometry':
case 'PlaneBufferGeometry':
geometry = new geometryConstructors[ data.type ](
data.width,
data.height,
data.widthSegments,
data.heightSegments
);
break;
Unfortunately not, any app that imports e.g. |
Was surprised that the
jsnext:main
field was not added with #9310, so this PR adds it.Adding this field will allow tools such as rollup (which is now used to bundle
three.js
itself) to perform tree-shaking optimization which might reduce bundle size considerably. See this.@Rich-Harris I know you have been pushing for
jsnext:main
usage a lot, was there a specific reason why you left this out from your PR?