English | 简体中文
Provide DX support for custom icon collections based on the Vscode extension antfu.iconify.
To install:
pnpm i -D unplugin-iconify-generatorFirst please install the Vscode extension antfu.iconify.
Thanks to unplugin, unplugin-iconify-generator offers synchronized support for multiple bundlers. For example, with Vite:
import Iconify from 'unplugin-iconify-generator/vite'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
Iconify({
collections: {
foo: './src/assets/icons'
}
}),
],
})According to the config above, assume that you have a icon bar.svg, put it into ./src/assets/icons/:
- By default, iconify-formatted JSON is generated in the
<root>/node_modules/.unplugin-iconify-generatorfolder by this plugin. - Then this plugin will modify
.vscode/settings.jsonto allowantfu.iconifyto fetch custom icons. This process is implemented usingjsonc-parser, which could preserve comments and maintain the configuration file format. - When typing
i-foo-barin the code, you can get corresponding code suggestions and icon thumbnails, wherefoois the prefix from the configuration, andbaris the filename of the icon. For more DX-related features, refer to the antfu.iconify documentation.
More details and options, please refer to the Options chapter below.
For more details plz refer to source code.
import { type IconifyIcon, parseIcon } from 'unplugin-iconify-generator'
// ...iconifyIntelliSense: A boolean value indicating whether to enable support for theantfu.iconifyextension. Note that enabling this will modify.vscode/settings.json. Default:true.cwd: An absolute path string specifying the root path, which will be used as the base path for other options. Default:process.cwd().output: A path string indicating where the generated metadata will be stored. Default:'./node_modules/.unplugin-iconify-generator'.collections: A required object where the key is a string representing the icon set prefix, and the value is a path string pointing to a folder. All.svgfiles within that folder will be considered as icons belonging to the specified icon set.
{
collections: {
foo: './src/assets/icons'
}
}Assume you have a icon './src/assets/icons/bar.svg', you can use it like:
i-foo-bar