Repository navigation
Enable tree-shaking in React package - #405
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/primer/octicons/mrcmjsqam |
emplums
left a comment
There was a problem hiding this comment.
YAYY 🙌 Would love to test a release candidate in Primer Components before we merge but other than that I think this looks good!
|
I can do the same later tonight for Memex. Do you have a package version handy that I can test with? |
|
dmarcey
left a comment
There was a problem hiding this comment.
This is awesome, thanks for the quick turn-around @colebemis !!
I can confirm that when using this package we dropped back down to just a couple kb higher than we were before consuming @primer/octicons-v2-react - a pretty good indicator that tree-shaking is working as expected.
Problem
Using a single icon from
@primer/octicons-v2-reactadds about 130kb to the bundle size of an application—so tree-shaking is not happening:@dmarcey wrote a detailed description of the problem in this issue: #404
Solution
Adding
"sideEffects": falseto thepackage.jsonand removing theiconsByNameandgetIconByNameexports seemed to fix the tree-shaking issue. I tested these changes in @dmarcey's tree-shaking-test repo and found that using one icon from@primer/octicons-v2-reactonly added 1.69kb to the bundle (verses 130kb before):Risks
Removing
iconsByNameandgetIconByNamefrom the React package would be a breaking change. Consumers would no longer be able to render a list of all the icons or dynamically get an icon component by name. However, @smockle noticed that there is only a single code match foriconsByNamein the entire GitHub org—and it’s from the deprecated package@githubprimer/octicons-react: https://github.com/search?q=org%3Agithub+iconsByName&type=Code. So maybe this breaking change wouldn't be disruptive.Closes #404