ui icon indicating copy to clipboard operation
ui copied to clipboard

Offline icons in Vite configuration

Open mateusznarowski opened this issue 1 year ago • 3 comments

Description

Hi, in a pure Vue 3 application where I am using Nuxt UI as a plugin in vite.config, I have a problem at the client, requests to the api to acquire icons are blocked so the icons do not display, is there any way to access offline / install the icon pack for these icons instead of acquiring them via api request?

Additional context

No response

mateusznarowski avatar May 16 '25 13:05 mateusznarowski

I'm not sure where you'd put this when using Nuxt UI as a Vite plugin. But for me adding all the Nuxt UI icons to the clientBundled icons in the Nuxt icon config did the job.

This is the part I am talking about:

//nuxt.config.ts
export default defineNuxtConfig({
  //...
  icon: {
    clientBundle: {
      icons: [
        // nuxt ui icons
        'lucide:arrow-left',
        'lucide:arrow-right',
        'lucide:check',
        'lucide:chevrons-left',
        'lucide:chevrons-right',
        'lucide:chevron-down',
        'lucide:chevron-left',
        'lucide:chevron-right',
        'lucide:chevron-up',
        'lucide:x',
        'lucide:ellipsis',
        'lucide:arrow-up-right',
        'lucide:folder',
        'lucide:folder-open',
        'lucide:refresh-cw',
        'lucide:minus',
        'lucide:plus',
        'lucide:search'
      ]
    },

Hope this helps :)

GlitchDevX avatar May 20 '25 17:05 GlitchDevX

Unfortunately no, the Nuxt version uses the @nuxt/icon component, and the Vite version uses the component from @iconify/vue. However, I found an option to disable requests to the api for a specific icon collection, below in the src/main.ts file I have provided the code:

// #1 Importing this function
import { addCollection } from '@iconify/vue'
// #2 Installing the appropriate icon collection in advance and importing it
import { icons as lucideIcons } from '@iconify-json/lucide'
import ui from '@nuxt/ui/vue-plugin'
import { createApp } from 'vue'

import App from './App.vue'
import router from './router'

// #3 And adding a collection
addCollection(lucideIcons)

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(ui)

app.mount('#app')

The only downside is that the budle grows significantly due to the addition of all the icons from lucide to the built application 😥. If anyone knows how to reduce/improve the impact of icons on the size of the application, I'd love such help 🙏

mateusznarowski avatar May 21 '25 15:05 mateusznarowski

The only advice I have is to use Nuxt for that 😅 That's the whole point of the @nuxt/icon module.

benjamincanac avatar May 23 '25 13:05 benjamincanac