Generate icon fonts from SVG files and automatically create CSS classes.
- Generate icon fonts from SVG files
- Automatic CSS class generation
- CLI and Node API support
- Customizable output structure
- Automatic icons preview page
npm install @epiled/icon-font-buildernpx @epiled/icon-font-builderimport { buildIcons } from "@epiled/icon-font-builder";
await buildIcons();After building the icons, include the generated CSS in your project:
<link rel="stylesheet" href="css/icons.css" />Then use the icons with CSS classes:
<i class="icon-add-user"></i>
<i class="icon-arrow"></i>src/
βββ icons/
| βββ add-user.svg
| βββ arrow.svg
Example using Gulp task runner.
import gulp from "gulp";
import { buildIcons } from "@epiled/icon-font-builder";
gulp.task("buildIcons", async function () {
await buildIcons();
});dist/
βββ css/
| βββ icons.css
βββ fonts/
| βββ Icons/
| βββ Icons.svg
| βββ Icons.ttf
| βββ Icons.woff
| βββ Icons.woff2
βββ icons-preview.html
@font-face {
font-family: "Icons";
src:
url("../fonts/Icons/Icons.woff2") format("woff2"),
url("../fonts/Icons/Icons.woff") format("woff"),
url("../fonts/Icons/Icons.ttf") format("truetype");
font-weight: normal;
font-style: normal;
font-display: swap;
}
[class^="icon-"],
[class*=" icon-"] {
font-family: "Icons" !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-add-user::before {
content: "\e001";
}
.icon-arrow::before {
content: "\e002";
}import gulp from "gulp";
import { buildIcons } from "@epiled/icon-font-builder";
gulp.task("buildIcons", async function () {
await buildIcons({iconsName: "Epl-Icons"});
});dist/
βββ Epl-Icons/
β βββ Epl-Icons/
β βββ Epl-Icons.svg
β βββ Epl-Icons.ttf
β βββ Epl-Icons.woff
β βββ Epl-Icons.woff2
βββ css/
β βββ epl-icons.css
βββ icons-preview.html
@font-face {
font-family: "Epl-Icons";
src:
url("../Epl-Icons/Epl-Icons/Epl-Icons.woff2")
format("woff2"),
url("../Epl-Icons/Epl-Icons/Epl-Icons.woff")
format("woff"),
url("../Epl-Icons/Epl-Icons/Epl-Icons.ttf")
format("truetype");
font-weight: normal;
font-style: normal;
font-display: swap;
}
[class^="icon-"],
[class*=" icon-"] {
font-family: "Epl-Icons" !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-add-user::before {
content: "\e001";
}
.icon-arrow::before {
content: "\e002";
}import gulp from "gulp";
import { buildIcons } from "@epiled/icon-font-builder";
gulp.task("buildIcons", async function () {
await buildIcons({
iconsName: "Icons-All", // required
inputDir: "src/icons",
outputDir: `dist/Icons-Output`,
font: {
fontName: "Icons-Font-Name",
folderName: "Icons-Folder-Name",
fontFileName: "Icons-Font-File-Name",
fontPath: "../Icons-Font-Path",
},
css: {
cssClass: "icon-all",
cssFileName: "icons-css-file-name",
},
templates: {
styles: {
generation: true,
outputDir: "dist",
},
preview: {
generation: true,
outputDir: "dist",
},
}
stripPrefix: "icon-", // removes "icon-" prefix from icon filenames
codepointsFile: ".icon-builder-cache",
});
});dist/
βββ Icons-Output/
β βββ Icons-Folder-Name/
β βββ Icons-Font-File-Name.svg
β βββ Icons-Font-File-Name.ttf
β βββ Icons-Font-File-Name.woff
β βββ Icons-Font-File-Name.woff2
βββ css/
β βββ icons-css-file-name.css
βββ icons-preview.html
@font-face {
font-family: "Icons-All";
src:
url("../Icons-Font-Path/Icons-Folder-Name/Icons-Font-File-Name.woff2")
format("woff2"),
url("../Icons-Font-Path/Icons-Folder-Name/Icons-Font-File-Name.woff")
format("woff"),
url("../Icons-Font-Path/Icons-Folder-Name/Icons-Font-File-Name.ttf")
format("truetype");
font-weight: normal;
font-style: normal;
font-display: swap;
}
[class^="icon-all-"],
[class*=" icon-all-"] {
font-family: "Icons-All" !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-all-add-user::before {
content: "\e001";
}
.icon-all-arrow::before {
content: "\e002";
}| Option | Type | Default | Description |
|---|---|---|---|
| iconsName | string | Icons | Name of the icon set |
| inputDir | string | src/icons | Source folder for SVG icons |
| outputDir | string | dist/fonts | Output directory |
| font.fontName | string | Icons | Font name |
| font.folderName | string | Icons | Folder name for font files |
| font.fontFileName | string | Icons | Font file base name |
| font.fontPath | string | ../fonts | Path to font in generated styles |
| css.cssClass | string | icon | CSS class prefix |
| css.cssFileName | string | icons | Name of generated CSS/SASS file (without extension) |
| templates.styles.generation | boolean | true | Enable or disable generation of style files (CSS/SASS) |
| templates.styles.outputDir | string | dist | Directory where generated style files will be written |
| templates.preview.generation | boolean | true | Enable or disable generation of the preview file (HTML demo) |
| templates.preview.outputDir | string | dist | Directory where the preview file will be written |
| formats | ("css" | "sass")[] | ["css"] | Style formats to generate when styles template is enabled |
| stripPrefix | string | null | null | Remove a prefix from icon names |
| codepointsFile | string | .icon-builder-cache | File path to store persistent icon codepoints |
- Node.js >= 22