nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.
https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue
MIT License
923 stars 51 forks source link

Custom collections aren't recognised #252

Open adjabaev opened 1 week ago

adjabaev commented 1 week ago

Hi, hope you're all doing well!

I ran into an issue using @nuxt/ui which now uses @nuxt/icon under the hood (used to work when icon collection names could be specified as nuxt/ui module args even tho i had to add a ts-ignore as it wasn't referenced in the enum type), I am using a custom iconify collection i built which goes by

"@iconify-json/as": "npm:@my-org-name/my-icon-collection@^0.0.2",

in my package.json which isn't referenced in https://github.com/nuxt/icon/blob/main/src/collection-names.ts thus making it uncompatible with @nuxt/icon. I think the issue comes from the usage of collectionNames there (as it seems we only values are only read if they are part of the underlying array): https://github.com/nuxt/icon/blob/cc14fe49b19fce023ba6f049984317492043c9ab/src/collections.ts#L72-L73 Would it be possible further expand the compatibility to include custom collections? (and eventually check if these are installed print an error on the logger if it isn't the case)

NOTE: It seems to work when using this configuration (note SSR isn't set to false which is a constraint I have)

icon: {
  serverBundle: {
    collections: [
      'as'
    ]
  }
}

but it the specific project is using this piece of config

[...]
ssr: false, // SSR forced to false
icon: {
  provider: 'server', // Tried with and without this
  serverBundle: {
    collections: [
      'as'
    ]
  }
}

Sorry if it is a bit long, I tried my best to keep it pleasant to read though. Thank you in advance! :)

antfu commented 1 week ago

Yeah I think that are the ways to use it. When ssr: false and provider is not set to server, the client will go to Iconify's API endpoint to ask for icons, which they don't have your custom iconset. The only way seems to serve it from your own server