Skip to content
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

Examples: convert Utils files to esmodules #22284

Merged
merged 11 commits into from
Aug 10, 2021
Merged

Conversation

marcofugaro
Copy link
Contributor

@marcofugaro marcofugaro commented Aug 6, 2021

Related issue: #22267

Description
I converted all *Utils files in the examples to esmodules to allow for tree-shaking. They now need to be imported like this:

import * as NURBSUtils from '../curves/NURBSUtils.js';

The files I touched are NURBSUtils, CameraUtils, SceneUtils, GeometryCompressionUtils, GeometryUtils, SkeletonUtils.

I had to move PackedPhongMaterial out of GeometryCompressionUtils as well.

@mrdoob mrdoob added this to the r132 milestone Aug 10, 2021
@mrdoob mrdoob merged commit 6276d11 into mrdoob:dev Aug 10, 2021
@mrdoob
Copy link
Owner

mrdoob commented Aug 10, 2021

Thanks!

@MickeyMiao7
Copy link

Related issue: #22267

Description I converted all *Utils files in the examples to esmodules to allow for tree-shaking. They now need to be imported like this:

import * as NURBSUtils from '../curves/NURBSUtils.js';

The files I touched are NURBSUtils, CameraUtils, SceneUtils, GeometryCompressionUtils, GeometryUtils, SkeletonUtils.

I had to move PackedPhongMaterial out of GeometryCompressionUtils as well.

Hi @marcofugaro, would you like to share any idea why this way can help with tree shaking? I am not sure about the difference under the hood and i am curious about it.

import * as NURBSUtils from '../curves/NURBSUtils.js';

@marcofugaro
Copy link
Contributor Author

@MickeyMiao7 basically, class methods are not tree-shakeable by bunders, while es-style exports are. There was no point in putting just functions under a class without using any of the class local state, so they've been converted to plain functions.

You can see an example of it in this short guide: https://esbuild.github.io/api/#tree-shaking

@MickeyMiao7
Copy link

@MickeyMiao7 basically, class methods are not tree-shakeable by bunders, while es-style exports are. There was no point in putting just functions under a class without using any of the class local state, so they've been converted to plain functions.

You can see an example of it in this short guide: https://esbuild.github.io/api/#tree-shaking

@marcofugaro Thanks you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants