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.

Tree-shaking not working as expected

See original GitHub issue

Current Behavior

When building a project with tsdx and exporting multiple things (all named exports), the dependencies (imports) of unused modules (that is, modules the consuming project does not import) all end up in the final consuming bundle. So, importing Thing1 will also import dependencies of Thing2 (even though Thing2 itself is tree-shaken away). I’m probably just doing something wrong or misunderstanding what’s possible, though.

Expected behavior

I was hoping that if I only import Thing1, Thing2’s dependencies (imports) would not be included in the final consuming bundle.

Suggested solution(s)

Unknown (so far), might not even be a bug.

Additional context

Reproduction (includes build output and webpack-bundle-analyzer):

https://github.com/wKovacs64/tsdx-treeshaking-test

I’ve gotten around this in the past with a Rollup config that takes all the source files as an array of inputs instead of a single entry point and outputs them all individually to a directory (Rollup output.dir) rather than a single output file (Rollup output.file like tsdx uses), but that may not be the right™️ solution nor does it look possible at the moment as tsdx does not currently support a customized Rollup configuration.

Your environment

Software Version(s)
TSDX 0.7.2
TypeScript 3.5.3
Browser N/A
npm/Yarn Yarn 1.17.3
Operating System Windows 10, macOS

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
maraisrcommented, Oct 3, 2019

Ah my bad - yeah… So what do you think, make those functions and we unlock tree shaking?

1reaction
TrySoundcommented, Oct 3, 2019

Pure annotation does not always work well. Why do you prefer elements instead of components? It’s a bit confusing since you called icons with capital first letter. With function components you will get customisation and treeshakability for free.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree shaking not working as expected? · Issue #10163 - GitHub
Using this in a react app, where the targeted component is lazy-loaded to try and isolate the ChartJS code into its own bundle....
Read more >
Webpack tree shaking not working as I expected
I read a lot of SO posts and the document however it doesn't work. I have files as follows: ./src/index.playground.js.
Read more >
Tree-Shaking a React Component Library in Rollup
In my understanding, "impure" in this case means that some import statements in your code contains side-effects, i.e. content not being used directly...
Read more >
Tree shaking - MDN Web Docs Glossary
Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code. ... Want to fix the...
Read more >
Building a Tree Shaking Friendly JavaScript Package
... “lodash” and not the whole library, and why did it work as expected with “lodash-es”? I think we are ready to talk...
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