-
-
Notifications
You must be signed in to change notification settings - Fork 739
lucide-svelte not working with SvelteKit #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@bejd I don't think is related to my issue, I am not using sveltekit, and my icons are loading, it's just loading every icon in the library compared to the two I am actually using via import. |
@bejd Thanks for reporting, with take a look! |
Confirming the issue with sveltekit. Is it possible, that vitejs/vite#8464 has relevance here? I tried the mentioned workarounds for the I am on Also this seems to be a similar report for |
@mpreu From what @ericfennis found it has to do with Vites tree-shaking. It's still including the whole module. |
I'm using this hacky workaround using svelte preprocess's replace until they fix their tree-shaking. Can't guarantee it'll work 100% of the time, but it shouldn't be too hard to add any edge cases. replace: [
[
/import\s*{\s*([^}]+?)\s*,?\s*}\s*from\s+['"]lucide-svelte['"](\s*;)?/gim,
(substring, /**@type {string} */ imports) => {
return imports
.split(/\s*,\s*/gim)
.map((s) => {
let icon = s.split(/\s+as\s+/);
let name = icon[1] || icon[0];
let file = icon[0].replace(/[A-Z]/g, (s) => '-' + s.toLowerCase()).slice(1);
return `import ${name} from 'lucide-svelte/dist/esm/icons/${file}.svelte';`;
})
.join('');
},
],
], Result: // From
import {
XOctagon,
MoreVertical,
ArrowUpDown,
Image as ImageIcon,
} from "lucide-svelte";
// To
import XOctagon from 'lucide-svelte/dist/esm/icons/x-octagon.svelte';
import MoreVertical from "lucide-svelte/dist/esm/icons/more-vertical.svelte";
import ArrowUpDown from "lucide-svelte/dist/esm/icons/arrow-up-down.svelte";
import ImageIcon from "lucide-svelte/dist/esm/icons/image.svelte"; |
Created a fix in #877. Beta release is released under |
Fixed by #877 |
This may be more a feature request than a bug, so apologies if it needs to be recategorised!
Prerequisites
Step to reproduce
Actual behavior
Icon components work.
Any message or error
Resources
The text was updated successfully, but these errors were encountered: