Skip to content

Icons ​

@weconstudio/nuxt registers @nuxt/icon with the client bundle enabled. Icons used by the app are embedded in the client bundle, so no request goes to the Iconify API at runtime and icons keep working offline.

Default configuration ​

The module sets these icon defaults; anything you put under icon in nuxt.config.ts is merged on top:

ts
icon: {
  clientBundle: {
    scan: {
      globInclude: ['**/*.{vue,js,ts}'],
      globExclude: ['node_modules', 'dist', 'build', 'coverage', 'test', 'tests', '.*'],
    },
    // with vuetify-nuxt-module: the icons used by Vuetify and by the module components
    icons: [/* 'mdi:magnify', 'mdi:close', ... */],
  },
},

Add icons that the scan cannot find (e.g. names built at runtime) to clientBundle.icons:

ts
icon: {
  clientBundle: {
    icons: ['mdi:account-circle', 'mdi:file-pdf-box'],
  },
},

Required dependencies ​

Install the Iconify JSON package of every icon set you use, at least MDI:

sh
pnpm add -D @iconify-json/mdi
sh
pnpm add -D @iconify-json/material-symbols # for each extra set

WARNING

Icons of a set whose @iconify-json/* package is not installed are not bundled.

With Vuetify ​

When vuetify-nuxt-module is installed, the module also:

  • registers a nuxtIcon Vuetify icon set backed by @nuxt/icon and makes it the default set, so <v-icon>mdi-close</v-icon> and icon="mdi-close" render through @nuxt/icon;
  • adds its own aliases, usable as $name ($search, $save, $trash, $refresh, $filter, $columns, $booleanOn, ...);
  • adds the Vuetify aliases ($close, $expand, $prev, ...) and the module aliases to clientBundle.icons, converting mdi-name to mdi:name, so the icons used inside Vuetify components are bundled even if they never appear in your source.

Without vuetify-nuxt-module none of this applies: use <Icon name="mdi:close" /> directly.

How it works ​

  1. The scan reads all .vue, .js and .ts files and collects the icon names it finds.
  2. With Vuetify, the alias icons are added to the list.
  3. The SVGs of the collected icons are taken from the installed @iconify-json/* packages and embedded in the client bundle.

Source Code ​