-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Treeshaking and dead code #1481
Comments
May be somewhat related to #1435. |
there's no tree shaking support for cjs code (lib/main.js) now. you should use esm (import/export). |
Ah, that makes sense, don't I feel stupid now? 😁 I'll work it out somehow with ES modules, thanks. 👍 |
Or not - I mean - it does work but it requires all modules to be ES modules which is almost impossible to obtain at this moment in the npm ecosystem. 😥 |
Yeah. that's my issue. Anyone know of something that can treeshake cjs? |
Hello, a very fast and very efficient bundler indeed but I am having issues with treeshaking, sorry in advance if I misunderstood the concept of treeshaking. Let me explain the issue; as all of us who use bundlers we install our 3rd-party modules and bundle them into a single file but what I'm seeing in that bundle file is a lot of dead code.
For example, let's say we have a library
X
that exports 2 functions and has some top-level variables (for whatever reason) which are only referenced in one of the 2 functions but I don't use that function, I use the other one - the one that doesn't reference any top-level variables.In my project
Y
I set up everything and bundle the code and I see all variables + all functions from libraryX
in the bundle file.Note that setting
sideEffects: false
in the libraryX
doesn't do anything.Is this the expected behaviour or am I missing something? Also, I've set up a repository for you to test - if you want to - it's located at igorskyflyer/esbuild-treeshaking. I've included the dist folder too so you don't have to build anything to begin with. 😄
P.S. don't judge me by my code in the
lib
folder, I never use quotes - only single quotes and I don't name my variables like that!!! 😂Thanks.
The text was updated successfully, but these errors were encountered: