Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bundle size increas using react icons

I noticed that using react-icons exponentially increases the bundle size. I have seen many questions on Stack Overflow, but none of them provided a satisfactory answer.

I have around 10 components that use a total of 20 icons from react-icons, and this increases the bundle size to 5MB.

Without using react-icons (but including 10 other custom icons in SVG format), the bundle size is only 495KB.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can you suggest a solution to reduce the bundle size while still using icons for my project?

example of usage

import { LuWheatOff, LuSalad } from "react-icons/lu";

>Solution :

What you’re encountering is likely an issue with your bundler being unable to treeshake the react-icons/lu import: which is why you see such a bloated size as the entire icon library is imported as long as you import a single component from it.

It seems that you might need to do a deep import from @react-icons/all-files instead: refer to their readme https://react-icons.github.io/react-icons/

import { LuSalad } from "@react-icons/all-files/lu/LuSalad";
import { LuWheatOff } from "@react-icons/all-files/lu/LuWheatOff";
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading