Next.js Discord

Discord Forum

The ultimate Icon component

Answered
PepeW posted this in #help-forum
Open in Discord
Avatar
I'm trying to create an Icon component that imports svgs dynamically without blowing up the bundle size.
I've gathered all the potential solutions we can find on the web, like require.context(), dynamic(), await import(), etc. but all of them are making the bundle size huge. Only one does not do that but it involves loading the svgs client side meaning that the svgs appear on the page after a delay.

I've set a repo with everything I tried but I still not have a good solution
The repo: https://github.com/pepew-le-boss/dynamic-icons-nextjs
Answered by PepeW
I've implement a good solution that is inspired from: https://github.com/shadcn-ui/ui/blob/main/apps/www/components/icons.tsx and doesn't need to read files so that doesn't blow up the bundle size
View full answer

1 Reply

Avatar
I've implement a good solution that is inspired from: https://github.com/shadcn-ui/ui/blob/main/apps/www/components/icons.tsx and doesn't need to read files so that doesn't blow up the bundle size
Answer