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.

(Partially) Broken tree shaking on v3.0.0-rc14

See original GitHub issue

Do you want to request a feature or report a bug?

A bug.

What is the current behaviour?

I’m currently using preact-feather as my icon library (and it is great) but noticed on an upgrade to v3.0.0-rc14 that the icons were no longer tree shaked. If you import one, you import them all. This increases the bundle size dramatically.

I don’t think this is preact-feather’s fault, as tree shaking did work before.

If the current behaviour is a bug, please provide the steps to reproduce.

I set up a quick example repository here. It is set to use v3.0.0-rc14 by default. Install, run yarn build:analyze and you’ll see that all icons are included. Downgrade to v3.0.0-rc10, run yarn build:analyze, and you’ll see only one, Mail, is included.

What is the expected behaviour?

Unused icons should not be added to the build.

Please mention other relevant information.

Environment Info:
  System:
    OS: Linux 5.6 Manjaro Linux
    CPU: (4) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 14.2.0 - /usr/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 6.14.5 - /usr/bin/npm
  Browsers:
    Firefox: 76.0.1
  npmPackages:
    preact: ^10.3.1 => 10.4.4 
    preact-cli: 3.0.0-rc.14 => 3.0.0-rc.14 
    preact-render-to-string: ^5.1.4 => 5.1.9

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
JoviDeCroockcommented, Jun 9, 2020

The issue is located here you are using CJS, due to the addition of custom babelrc files for buliding this is now transpiling your code to CJS making it effectively impossible to tree shake.

To enable tree-shaking this should have modules: false

More documentation on custom babel configs

0reactions
rschristiancommented, Jun 10, 2020

Yeah, seems great. Thanks for your help. Appreciate it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree shaking and code splitting in webpack - LogRocket Blog
What is tree shaking? Tree shaking, also known as dead code elimination, is the practice of removing unused code in your production build....
Read more >
Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module...
Read more >
Tree-Shaking: A Reference Guide - Smashing Magazine
Simply put, tree-shaking means removing unreachable code (also known as dead code) from a bundle. As Webpack version 3's documentation states: ...
Read more >
Deep Dive Into Tree-Shaking - JavaScript in Plain English
In the JavaScript world, the term tree-shaking refers to the removal of dead code. But this terminology is not limited to JavaScript, ...
Read more >
Build a Tree-Shaking Utility in JavaScript | by Chidume Nnamdi
js file and the mul function has fallen off ;-). Let's dive into technical details on how to build our tree-shaker. First, we...
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