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

SideEffects false #21663

Closed
DefinitelyMaybe opened this issue Apr 16, 2021 · 6 comments
Closed

SideEffects false #21663

DefinitelyMaybe opened this issue Apr 16, 2021 · 6 comments

Comments

@DefinitelyMaybe
Copy link
Contributor

Re package.json with sideEffects = false, there are a bunch of /*@__PURE__*/ comments around the code that I think we can safely get rid of? would that be correct @marcofugaro ?

I can make a PR for it if so.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 16, 2021

Related #16059.

@marcofugaro
Copy link
Contributor

Not quite, sideEffects: false just tells the bundler that we don't attach anything to the window or any other global scopes.

It's up to the bundler to understand what to remove and what not to. From the webpack tree-shaking guide:

Terser actually tries to figure it out, but it doesn't know for sure in many cases. This doesn't mean that terser is not doing its job well because it can't figure it out. It's just too difficult to determine it reliably in a dynamic language like JavaScript.

We can actually test this now, the test-treeshake script is testing importing three.js like if it was a npm module:

import * as THREE from '../..';

If you remove all /*@__PURE__*/ and run npm run build && npm run test-treeshake you can see the threeshaken bundle size actually increase.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 16, 2021

It seems there was also some confusion about the sideEffects flag in #16059. According to my understanding, we can safely ignore it since the key for better tree-shaking is code refactoring (what we did in the last couple of month).

@marcofugaro
Copy link
Contributor

@Mugen87 better to test its effects with common bundlers first.

I tested it months ago with webpack (just by removing the flag in node_modules/three/package.json) and it was tree-shaking correctly even without the flag. Have to check if it's the same with this next release.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 16, 2021

Sounds good!

@DefinitelyMaybe
Copy link
Contributor Author

thank you all

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

No branches or pull requests

3 participants