Dynamic named imports using variables doesn't work with tree shaking #17933
HunterMeyer
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My app displays social media links and specifies the icon to display with each link.
I'm using the oh-vue-icons icon library. If you import the whole thing, it's huge.
So I want to import only the icons I have defined links for.
However, when I try to do the dynamic imports, it breaks tree shaking and I'm left with the entire library.
Here's my
/src/data/social-links.js
where I define the links and their icon name:Now in my Vue code,
SocialLinks.vue
, I have:I have also tried an alternative approach in
importIcons
. But it didn't work either:This works on the front-end code, however, tree shaking doesn't work.
I imagine this has something to do with not being able to evaluate the runtime code. But perhaps there's something I can do as a pre-build step?
Beta Was this translation helpful? Give feedback.
All reactions