json-package
title: Exporting JSON Packages
types:
IconSet: '../icon-set/index.md'
IconifyJSON: '/docs/types/iconify-json.md'
Exporting icon set as JSON package
This tutorial is part of export functions documentation in Iconify Tools.
Function [func]exportJSONPackage() creates an icon package in specified directory.
These packages are used to load an entire icon sets, like this:
import { addCollection, Icon } from '@iconify/react';
import { icons as mdiLightIcons } from '@iconify-json/mdi-light';
import { icons as tablerIcons } from '@iconify-json/tabler';
addCollection(mdiLightIcons);
addCollection(tablerIcons);
// Demo using some of imported icons
export function renderHomeIcon() {
return <Icon icon="mdi-light:home" />;
}
export function renderAlertIcon() {
return <Icon icon="tabler:alert-octagon" />;
}
[npm]@iconify-json/mdi-light and [npm]@iconify-json/tabler are packages generated by this function, used in example above.
See individual icon set packages documentation for details.
Usage
Function has the following parameters:
[prop]iconSet,[type]IconSet. Icon set to export.[prop]options,[type]object. Options. See below.
Function returns array of generated files.
Function is asynchronous. That means you need to handle it as [class]Promise instance, usually by adding [js]await before function call.
Options
Options object has the following mandatory property:
[prop]target,[type]string. Target directory. If directory is missing, it will be created.
and the following optional properties:
[prop]cleanup,[type]boolean. Iftrue, target directory will be emptied before exporting icons. Default isfalse.[prop]package,[type]object. Properties for[file]package.json. Use this to set at least package name and version.[prop]customFiles,[type]Record<string, unknown>. Custom files to export. Key is filename, value is content. See below.
customFiles
[prop]customFiles option contains additional files you want to add to package. Key is filename, value can be one of these types:
[type]string. Content of file.[type]object. JSON content that will be serialized before writing file.[type]null. If value is[type]null, file is deleted.
Example
src: libraries/tools/export/json-package.ts
title: 'example.ts'