A Vite plugin (v1.4.10) that tree-shakes Lucide icons by transforming non-tree-shakable imports like `import { IconName } from '@lucide/svelte'` into explicit path imports like `import IconName from '@lucide/svelte/icons/icon-name'`. Supports Vite 2+, Rollup 1+, and Rolldown. Features an auto-updater to handle renamed or deprecated Lucide icons automatically. Ships TypeScript types. Compared to manual import rewriting, it automates the process and works across any framework (React, Vue, Svelte, etc.) with Vite.
npm install vite-plugin-lucide-preprocessVerified import paths — ran on the pinned version, not inferred.
Adds the plugin to Vite config and demonstrates auto tree-shaking of Lucide icons in a Svelte component.
Ensure lucidePreprocess() is the first plugin in the array.
Only use with Lucide icon packages.
Wait for the auto-updater or manually update icon names in your code. Check the Lucide changelog.
Test source maps in development and production. Reorder plugins if needed.
Use the default import: import lucidePreprocess from 'vite-plugin-lucide-preprocess' and add it to plugins: [lucidePreprocess()].
Install the package: npm install -D vite-plugin-lucide-preprocess and add lucidePreprocess() to the plugins list.
Run the auto-updater (wait for it) or verify you have the correct icon name from Lucide documentation. Ensure @lucide/svelte is installed.