Skip to content
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

Improve tree shaking friendliness #224

Closed
shawnbot opened this issue Jul 11, 2018 · 4 comments
Closed

Improve tree shaking friendliness #224

shawnbot opened this issue Jul 11, 2018 · 4 comments

Comments

@shawnbot
Copy link
Contributor

@josh and I discussed some of the more nuanced ways that we might be able to make @github/octicons-react more friendly to tree-shaking. One thing we could try is separating out the iconsByName and getIconByName() symbols in a separate file, which would exclude the key/component mapping from the bundle altogether, making it possible for uglify to remove the unused components as dead code.

@shawnbot
Copy link
Contributor Author

shawnbot commented Oct 5, 2018

Another option would be to put each component into its own file so that folks using tools that don't properly tree-shake or remove dead code get use only the icons they need:

import Octicon from '@primer/octicons'
// by key
import GitHub from '@primer/octicons/mark-github'
// or by generated class name?
import GitHub from '@primer/octicons/MarkGithub'

@shawnbot
Copy link
Contributor Author

shawnbot commented Nov 16, 2018

It sounds from this comment like webpack's problem is tree-shaking at the module level, as opposed to the file level; and that the solution is to ship each icon class as a separate file and re-export those from dist/index.esm.js:

// dist/icons/X.js
export default function X() { /* ... */ }

// dist/index.js
export {default as X} from './icons/X'

@Daniel15
Copy link

Just noticed today that adding a single Octicons icon to my app increases its bundle size by 68 KB :/

image

Are there any plans to support tree shaking?

@shawnbot shawnbot removed their assignment Jan 29, 2020
@colebemis
Copy link
Contributor

@primer/octicons-react should now be tree-shakeable 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

3 participants