alphapeter / fa-svelte

Font Awesome 5 for svelte.js
MIT License
71 stars 3 forks source link

Question: Is it possible to dynamically import only needed icons? #16

Closed VladimirHumeniuk closed 4 years ago

VladimirHumeniuk commented 4 years ago

Is it possible to dynamically import only needed icons? For example, if I don't know which exactly icons will be used in component, and the icons names came as a strings from the server, should I just import all icons like this:

import * as icons from '@fortawesome/free-solid-svg-icons/';

And then use as:

<Icon icon={icons[key]}>

?

But i'm afraid in this case I will add to the bundle all FA icons. Is there any solution to do it properly?

Thaks

alphapeter commented 4 years ago

I think what you are looking for is called tree shaking. The purpose of tree shaking is to remove dead code afterwards.

I can't help you with that though since I have no successful experience using it with font awesome icons.

But if you succeed, please share your experience.