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

Doesn't tree shake when bundled with Webpack and Create React App #574

Closed
thomscoder opened this issue Jul 4, 2022 · 8 comments
Closed

Comments

@thomscoder
Copy link

Describe the bug
React-icons 4.2.0 when bundled with Webpack is importing the entire libraries even when specified to import just one icon. Resulting in 95% of unused code.

import { CgArrowsShrinkH as Shrink } from 'react-icons/cg'

Expected behavior
I'm expecting to see only the Shrink icon imported.

Screenshots
Screenshot 2022-07-04 100908

Version: 4.2.0
OS: Windows 10
Browser: Chrome 102.0.5005.11

@codsane
Copy link

codsane commented Jul 5, 2022

You may need to import from @react-icons/all-files instead as described here: #154 (comment)

@thomscoder
Copy link
Author

You may need to import from @react-icons/all-files instead as described here: #154 (comment)

Oh alright, will do. Thank you very much @codsane

@fregante
Copy link

I'm experiencing this issue through https://github.com/rjsf-team/react-jsonschema-form

To the point that most of the weight comes from react-icons, a sub-dependendency of react-jsonschema-form. I looked at their code and they're using the same code suggested in your readme. How come it's failing? Other libraries are being treeshaken, like Lodash.

Screen Shot 11

@fregante
Copy link

fregante commented Aug 25, 2022

As seen by the recent comments and mentions in #154, this issue persists and I think it should be fixed in the main package instead of forcing people to discover this on their own and have to fix it every time.

@thomscoder
Copy link
Author

As seen by the recent comments and mentions in #154, this issue persists and I think it should be fixed in the main package instead of forcing people to discover this on their own and have to fix it every time.

I agree.
Switched to another package for now.

Thanks to you both, guys!

@villesau
Copy link

What is @react-icons/all-files? Looks like it's not been updated in years.

@codsane
Copy link

codsane commented Dec 30, 2022

What is @react-icons/all-files? Looks like it's not been updated in years.

@villesau Unfortunately it seems this is due to a limitation with the number of files allowed in a package, see #593 and #568.

@villesau
Copy link

Could make sense to publish all the icon packs as treeshakeable individual packages then 🤔 such as @react-icons/md etc.

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

No branches or pull requests

5 participants