Templarian / MaterialDesign-JS

Dist for Material Design Icons JS/TypeScript
Other
161 stars 18 forks source link

Question dynamic import treeshaking #19

Closed stephenjason89 closed 3 years ago

stephenjason89 commented 3 years ago

Hello I have the following code to dynamically import the icon. Only problem is, it doesn't treeshake. Is there a way to make dynamic import treeshaking?

image

mririgoyen commented 3 years ago

The point of tree-shaking is to remove all code that doesn't get used. If you don't know which icons you will or will not use, how can tree-shaking do it's thing?

stephenjason89 commented 3 years ago

The point of tree-shaking is to remove all code that doesn't get used. If you don't know which icons you will or will not use, how can tree-shaking do it's thing?

Yes, you are completely right. It can't, found it the hard way 😅 I came up with a different approach and use all .svg icons file and reference it in an img tag. Instead of importing it, i just change the url.

I'll be closing this issue now 🙂