-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
carbon-components is not amenable to tree-shaking #5980
Comments
Thanks @s100 for your thoughts and analysis. Need to learn how Meanwhile, if you do the following at one of the your project where > npm i -g rollup @rollup/plugin-node-resolve rollup-plugin-commonjs rollup-plugin-terser
> echo "import { Loading } from 'carbon-components'; console.log('Loading:', Loading);" | rollup --format iife -p @rollup/plugin-node-resolve -p 'commonjs={"include":["node_modules/**"]}' -p terser | gzip -c | wc -c You'll get:
Not on-par to fully-tree-shaken result (due to a 3rd party library not defined as pure), but some improvements. If you replace |
Duplicate of #4881 I think, agreed that there is definitely room to improve here. Certain dependencies might be unable to be tree-shaken but we can definitely improve what exists out there now. |
I have discovered that import { iconAdd } from 'carbon-icons'
console.log(iconAdd) then If I add |
Actually, on reflection, it seems that |
Closing as resolved/dup of #4881, feel free to reopen if you feel that is not the case 🙂 |
What package(s) are you using?
carbon-components
carbon-components-react
Detailed description
Bundle sizes involving
carbon-components
(including when used viacarbon-components-react
) are a lot larger than I expect them to be because there seems to be no tree-shaking going on incarbon-components
.Create a file
entry.js
reading as follows:Then at the command line:
You'll find
output1.js
is in the vicinity of 111kB, and at a glance appears to contain the entirety ofcarbon-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.Here, we find that
output2.js
is more like 11kB, contains only theLoading
component and its one or two required modules.No.
I am not going to suggest that adding
"sideEffects": false
tocarbon-components
'package.json
is the entire solution here, there's obviously a lot of different externalities and testing to think about...carbon-components@10.11.2
The text was updated successfully, but these errors were encountered: