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.

carbon-components is not amenable to tree-shaking

See original GitHub issue

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you’re having.

Bundle sizes involving carbon-components (including when used via carbon-components-react) are a lot larger than I expect them to be because there seems to be no tree-shaking going on in carbon-components.

Create a file entry.js reading as follows:

import { Loading } from 'carbon-components'
console.log(Loading) // don't render, just log

Then at the command line:

npm install carbon-components webpack webpack-cli
npx webpack entry.js --output output1.js --mode production

You’ll find output1.js is in the vicinity of 111kB, and at a glance appears to contain the entirety of carbon-components.

Next, open node_modules/carbon-components/package.json and add a property "sideEffects": false here. Save it and go back to the command line.

npx webpack entry.js --output output2.js --mode production

Here, we find that output2.js is more like 11kB, contains only the Loading component and its one or two required modules.

Is this issue related to a specific component?

No.

What did you expect to happen? What happened instead? What would you like to see changed?

I am not going to suggest that adding "sideEffects": false to carbon-componentspackage.json is the entire solution here, there’s obviously a lot of different externalities and testing to think about…

What version of the Carbon Design System are you using?

carbon-components@10.11.2

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
s100commented, May 11, 2020

Actually, on reflection, it seems that carbon-icons hasn’t been updated for two years… So, I think “upgrade to @carbon/icons-react” is an acceptable response to that particular issue. That’s what we plan to do. The query with carbon-components remains though.

1reaction
s100commented, Apr 30, 2020

I have discovered that carbon-icons@7.0.7 has exactly the same issue. If entry.js reads:

import { iconAdd } from 'carbon-icons'
console.log(iconAdd)

then npx webpack entry.js --output output1.js --mode production yields an 88kB bundle containing every single Carbon icon.

If I add "sideEffects": false to carbon-iconspackage.json, the result is 1.15kB and contains only the icon I used.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree-Shaking Problems with Component Libraries - Medium
Tree -shaking isn't magic, and much like the garbage collector, you need to understand a little of what it's doing to get the...
Read more >
Tree Shaking simplified with Webpack! - Opcito
Learn the procedure of tree shaking with the help of webpack. We also explain the principles behind tree shaking to derive it's advantages....
Read more >
Untitled - Fair World Project
Fair World Project is a non-profit that advocates for fair trade policies that support small-scale farmers, artisans, and workers. We publish the.
Read more >
Solazyme: In The Wrong Place At The Wrong Time (OTCMKTS ...
I think the anonymous author and empty arguments tell us that this is some tree-shaking/ bear-raiding, no authentic attempt at a fair evaluation...
Read more >
Optimization of a phenol extraction-based protein preparation ...
Request PDF | Optimization of a phenol extraction-based protein preparation method amenable to downstream 2DE and MALDI-MS based analysis of bacterial ...
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