icon-package
title: Exporting Icon Packages
types:
IconSet: '../icon-set/index.md'
Exporting icon set as icon package
This tutorial is part of export functions documentation in Iconify Tools.
Function [func]exportIconPackage() creates icon package in specified directory.
These packages are used in offline icon components, like this:
src: icon-components/common/offline.jsx
[npm]@iconify-icons/bi is a package generated by this function, used in example above.
See split icon packages documentation for details.
Deprecation notice
This function is deprecated, but it is still maintained for developers that do rely on it.
Single icon packages were needed in the early stages of Iconify project. In the modern Node ecosystem, this is no longer needed. Tools like Vite can be used to generate content on demand, including single file packages. Packages like Unplugin Icons dynamically generate icon components.
Single icon packages are no longer needed and should be avoided. If you need to extract data for few icons, do it during the build process of your app as either a custom script or a Vite plugin.
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
The [prop]options object has the following mandatory property:
[prop]target,[type]string. Target directory. If a 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]module,[type]boolean. Iftrue, function generates package with ES modules, iffalse, function generates package with CommonJS modules. Default istrue.[prop]typesContent,[type]string. Custom content of[file].d.tsfiles.[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/icon-package.ts
title: 'example.ts'
谢谢你的反馈!