Skip to content
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

feat(lucide-svelte): Aliased imports for direct imports #2584

Merged
merged 7 commits into from
Nov 15, 2024

Conversation

ericfennis
Copy link
Member

Closes #2580

What is the purpose of this pull request?

  • New Icon
  • New Feature
  • Documentation update

Description

This is a new setup for the build process, making importing aliased imports possible.

// This is working
import AlertCircle from "lucide-svelte/icons/alert-circle";
import CircleAlert from "lucide-svelte/icons/circle-alert";

To make it work I had to make some additions to the build process that generates the aliases files.
The .ts file addition is needed to point to the correct icon files.
I've tried to do it just with .svelte files, but there is a difference in how Sveltekit and Vite read the imports map in package.json. Sveltekit ignores the default in the imports map when it tries to do SSR.

Current output:
image

Note: The build scripts are getting a bit complex, some refactoring in the future will be nice.

@github-actions github-actions bot added 🧳 lucide package About the lucide package 🧣 svelte package About the Svelte package labels Nov 5, 2024
@ericfennis
Copy link
Member Author

ericfennis commented Nov 5, 2024

I've published a beta version on [email protected] for testing.

@ericfennis ericfennis changed the title Fix svelte alias specific imports feat(lucide-svelte): Aliased imports for direct imports Nov 5, 2024
@ericfennis ericfennis marked this pull request as draft November 5, 2024 08:55
@ericfennis ericfennis merged commit 09cebe1 into main Nov 15, 2024
19 of 20 checks passed
@ericfennis ericfennis deleted the fix-svelte-alias-specific-imports branch November 15, 2024 12:52
@kaechele
Copy link

This unfortunately broke lucide-svelte:

✘ [ERROR] Could not resolve "../icons/wand-2.ts"

    node_modules/.pnpm/[email protected][email protected]/node_modules/lucide-svelte/dist/aliases/prefixed.js:3364:30:
      3364 │ default as LucideWand2 } from '../icons/wand-2.ts';
           ╵                               ~~~~~~~~~~~~~~~~~~~~

Error: Build failed with 3668 errors:
node_modules/.pnpm/[email protected][email protected]/node_modules/lucide-svelte/dist/aliases/aliases.js:8:38: ERROR: Could not resolve "../icons/alarm-check.ts"
node_modules/.pnpm/[email protected][email protected]/node_modules/lucide-svelte/dist/aliases/aliases.js:10:38: ERROR: Could not resolve "../icons/alarm-minus.ts"
node_modules/.pnpm/[email protected][email protected]/node_modules/lucide-svelte/dist/aliases/aliases.js:12:37: ERROR: Could not resolve "../icons/alarm-plus.ts"
node_modules/.pnpm/[email protected][email protected]/node_modules/lucide-svelte/dist/aliases/aliases.js:14:39: ERROR: Could not resolve "../icons/arrow-down-az.ts"
node_modules/.pnpm/[email protected][email protected]/node_modules/lucide-svelte/dist/aliases/aliases.js:16:39: ERROR: Could not resolve "../icons/arrow-down-za.ts"

dist/aliases/prefixed.js references the icon.ts files, which don't exist in the lucide-svelte distribution. Previous versions referenced the .svelte files, which do exist in the distribution.

@ericfennis
Copy link
Member Author

@kaechele is this still happening when removing and reinstalling npm packages?

@kaechele
Copy link

Yes, this still happens even on a completely fresh checkout of my project. Looking at the contents of the lucide-svelte package on npmjs.com I can see that the .ts files are not there either: https://www.npmjs.com/package/lucide-svelte?activeTab=code

@kyle-leonhard
Copy link

I was hit by this as well in version 0.458.0: #2614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧳 lucide package About the lucide package 🧣 svelte package About the Svelte package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lucide-svelte does not implement alias for icons
3 participants