Skip to content

Exporting icons to directory

This tutorial is part of export functions documentation in Iconify Tools.

Function exportToDirectory() writes all icons in IconSet instance to a specified directory.


Function has the following parameters:

  • iconSet, IconSet. Icon set to export.
  • options, object. Options. See below.

Function returns array of stored icons.

Function is asynchronous. That means you need to handle it as Promise instance, usually by adding await before function call.


The options object has the following mandatory property:

  • target, string. Target directory. If a directory is missing, it will be created.

and the following optional properties:

  • cleanup, boolean. If true, target directory will be emptied before exporting icons. Default is false.
  • autoHeight, boolean. If true, icons will have dimensions matching viewBox. If false, icons will have height set to "1em". Default is true.
  • includeAliases, boolean. Generates files for aliases. Default is true.
  • includeChars, boolean. Generates files for characters, such as f00.svg for icon that has character "f00" assigned to it. Default is false.
  • log, boolean. If true, function logs process. Default is false.


tsimport { exportToDirectory, IconSet } from '@iconify/tools';

(async () => {
   // Import icons
   const iconSet = new IconSet({
       prefix: 'test',
       icons: {
           maximize: {
               body: '<g fill="currentColor"><path d="M3 3v10h10V3H3zm9 9H4V4h8v8z"/></g>',
           minimize: {
               body: '<g fill="currentColor"><path d="M14 8v1H3V8h11z"/></g>',
       width: 24,
       height: 24,

   // Export all icons
   await exportToDirectory(iconSet, {
       target: `output/${iconSet.prefix}`,
       log: true,

Released under the Apache 2.0 License.