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

Automatically include all statically-referenced icons #191

Open
mikestopcontinues opened this issue Jan 10, 2024 · 2 comments
Open

Automatically include all statically-referenced icons #191

mikestopcontinues opened this issue Jan 10, 2024 · 2 comments

Comments

@mikestopcontinues
Copy link

mikestopcontinues commented Jan 10, 2024

What version of astro-icon are you using?

v1.0.2

Astro Info

Astro                    v4.1.1
Node                     v18.19.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/vercel/serverless
Integrations             auto-import
                         @astrojs/mdx
                         @astrojs/preact
                         @astrojs/alpinejs
                         astro-icon
                         @astrojs/tailwind
                         @astrojs/partytown

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I use quite a few icons from my preferred icon set, but I don't use them all. However, every single icon can be inferred from static analysis of my ./src directory.

What's the expected result?

Automatically including all icons that match the following criteria:

  1. If an icon pack is installed @iconify-json/[iconset]
  2. And the pattern /(iconset):(?<icon>[a-z-]+)/ appears anywhere within ./src
  3. And [icon] is exported from @iconify-json/[iconset]
  4. Include it in the bundle.

Also include any icons explicitly listed in astro.config.ts.

What do you think?

Link to Minimal Reproducible Example

N/A

@natemoo-re
Copy link
Owner

This is an interesting idea! It could definitely work, but I'm obviously hesitant to try to write code that handles all the possible edge cases here and can operate on every possible file type. For example, Astro gets a lot of support questions about Tailwind not supporting dynamic expressions because of the similar strategy they use. It's not the most intuitive behavior IMO.

A similar effort by @antfu called PurgeIcon has since been abandoned, I assume due to the maintenance burden of such complex behavior.

In my opinion, explicit opt-in is almost always a better choice than implicit magic.

@hrvstr
Copy link

hrvstr commented Apr 5, 2024

This would be a really neat feature but I understand that there are too many edge cases to build something like this.

How are you handling explicitly listing icons on larger projects? I have quite a long list of icons in my projects, and maintaining it is a lot of effort. This is especially hard when coming back to an older project. I have to go through all the components and check what icons are used.

Maybe we can do this the other way around and create a script that lists which icons are required to build the project. Let's say I remove all icons from the config file and run the build command. The build fails and I get a list of all missing icons that I can then explicitly list in my config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants