unplugin / unplugin-icons

🤹 Access thousands of icons as components on-demand universally.
https://www.npmjs.com/package/unplugin-icons
MIT License
4.06k stars 144 forks source link

Support a default collection for auto-import #69

Open kmohrf opened 3 years ago

kmohrf commented 3 years ago

Hi,

I was looking for something like a defaultCollection option for the IconsResolver but that doesn’t seem to exist yet. I usually try to stick to one icon collection in any single project, simply because the general art style is consistent and only use icons from other collections as kind-of last resort (though unplugin-icons definitively makes this much easier, thank you!).

Right now I’ve been using the system-uicons and it gets a little tedious to write <icon-system-uicons-plus/> when it probably could be <icon-plus/> instead and only if I want to deviate from my default I’d have to write something like <icon-mdi-account/>.

I thought I could get away with

IconsResolver({
  prefix: 'icon',
    alias: {
      '': 'system-uicons',
    }
})

but… curse this sudden but inevitable betrayal :).

Thank you for time & work,

Konrad

versions used: vite@2.5.10 unplugin-icons@0.11.3

userquin commented 3 years ago

@kmohrf Maybe you can use aliases in combination with enable only your collection:

userquin commented 3 years ago

@kmohrf just use this:

Icons({
  compiler: 'vue3',
}),
Components({
  dts: true,
  resolvers: [
    IconsResolver({
      prefix: '',
      alias: {
        sys: 'system-uicons',
      },
      enabledCollections: ['system-uicons'],
    }),
  ],
}),

then

<sys-plus/>

EDIT: or just try this one, maybe just works:

Icons({
  compiler: 'vue3',
}),
Components({
  dts: true,
  resolvers: [
    IconsResolver({
      prefix: '',
      alias: {
        icon: 'system-uicons',
      },
      enabledCollections: ['system-uicons'],
    }),
  ],
}),

then

<icon-plus/>
kmohrf commented 3 years ago

Yeah I thought about that too and it probably works, but has very weird semantics because then I have <icon-plus/> and <mdi-something/> which would confuse others working on the same project. Apart from that I don’t want to restrict the enabled collections I just want one of them to be the default.

I don’t think this is a must have. I currently have aliased system-uicons to sui which is probably fine, I just thought it makes a reasonable addition configuration-wise. If you think this is over-engineered feel free to close it :).

antfu commented 3 years ago

PR welcome if you really need that.