question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SideEffects false

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marcofugarocommented, Apr 16, 2021

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:

https://github.com/mrdoob/three.js/blob/c9350382c50e549c0d2960041448ffe652bbbd9b/test/treeshake/index.js#L1

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

0reactions
DefinitelyMaybecommented, Apr 16, 2021

thank you all

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree Shaking - webpack
All the code noted above does not contain side effects, so we can mark the property as false to inform webpack that it...
Read more >
What Does Webpack 4 Expect From A Package With sideEffects
The "sideEffects": false flag in big-module's package.json indicates that the package's modules have no side effects (on evaluation) and ...
Read more >
false flag to package.json to allow tree shaking · Issue #16059 ...
Consider adding "sideEffects": false to package.json so that bundlers like webpack are able to tree shake three.js.
Read more >
Everything you never wanted to know about side effects
In this blog post I'll explain what side effects are, why webpack needs to ... In that situation, you can simply set sideEffects...
Read more >
Tree Shaking Examples - Katerina198b
In this example, the final bundle must contain sideEffect.js module, ... side effects you can to drop them with /*#__PURE__*/ or sideEffects: false...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found