@lucide/svelte: export per-icon __iconData (follow-up to #4644 / #4761)
Problem
Follow-up to #4644, closed by #4761. That PR gave lucide-preact, lucide-solid and lucide-react-native the same per-icon data export that lucide-react and lucide-vue-next already had:
export { __iconData, PanelLeft as default };@lucide/svelte was not included and is still the only framework package with no way to read an icon's geometry. Libraries that interpolate between icons (morphing, path animation, custom renderers) need the IconNode upfront, so a compiled component is useless to them, and they still have to install core lucide alongside @lucide/svelte — the exact duplication #4644 describes.
Verified on @lucide/[email protected]
dist/icons/panel-left.js only re-exports the component:
export { default } from "./panel-left.svelte";The geometry exists but stays private inside the generated component:
<script lang="ts">
import Icon from '../Icon.svelte';
let props = $props();
const iconData = { "name": "panel-left", "size": 24, "node": [...], "aliases": ["sidebar"] };
</script>grep -r "__iconData\|__iconNode" @lucide/svelte/dist→ no matches- the shipped
dist/icons/panel-left.svelte.d.tsexports onlydefault LucideIconDatais exported as a type from the package root, but no value of that type is reachable
Compare with the same version of the other packages:
[email protected] dist/esm/icons/panel-left.mjs -> export { __iconData, PanelLeft as default };
[email protected] dist/esm/icons/panel-left.mjs -> export { __iconData, PanelLeft as default };So the natural consumer import simply has nothing to import:
import PanelLeft, { __iconData } from '@lucide/svelte/icons/panel-left'; // no exported member '__iconData'Root cause
Two places, both narrow:
packages/svelte/scripts/exportTemplate.mtsnever emits a data export — it only rendersconst iconData: LucideIconData = {...}privately, in the instance script.tools/build-icons/building/generateIconFiles.tshardcodes the separate icon shim for every icon:
const output = `export { default } from "./${iconName}${iconFileExtension}";\n`;So even adding export const __iconData to the .svelte file would not reach dist/icons/*.js. @lucide/svelte is currently the only package using separateIconFileExport, so this needs care rather than a blanket change.
Proposal
Match the other packages: export the icon data per icon.
import PanelLeft, { __iconData } from '@lucide/svelte/icons/panel-left';
// __iconData: LucideIconData -> { name, size, node, aliases }Sketch for the template (module script, so it is a real module export and stays tree-shakeable):
<script module lang="ts">
import type { LucideIconData } from '../types.js';
export const __iconData: LucideIconData = {...};
</script>Plus either make the shim re-export it, e.g. export { default, __iconData } from "./panel-left.svelte";, or add a dedicated data subpath — happy to defer to whatever fits the build best.
TODO
- Export
__iconData(and, if we want parity withlucide-react, a deprecated__iconNode = __iconData.node) from the per-icon module inpackages/svelte/scripts/exportTemplate.mts. - Make the separate icon file shim in
tools/build-iconsre-export those named exports instead of onlydefault, without changing output for packages that only need the default. - Keep
@lucide/svelte/icons/*tree-shakeable and add no data to the barrel, since the current barrel ships no geometry. - Add a test in
packages/svelte/testsasserting__iconDatais present and matches the icon's nodes, and that the component still renders after the template change. - Document the per-icon data import in the Svelte package guide.
Happy to open the PR if someone points me at the preferred shape (template export vs separate data subpath).
Source: lucide-icons/lucide