Create an SVG font from several SVG icons with Gulp.
First, install gulp-svgicons2svgfont
as a development dependency:
npm install --save-dev gulp-svgicons2svgfont
Then, add it to your gulpfile.js
:
var svgicons2svgfont = require('gulp-svgicons2svgfont');
gulp.task('Iconfont', function(){
gulp.src(['assets/icons/*.svg'])
.pipe(svgicons2svgfont({
fontName: 'myfont'
}))
.on('codepoints', function(codepoints) {
console.log(codepoints);
// Generate CSS/SCSS for your codepoints
// Codepoints is an array of objects, each item has the properties "name", "codepoint" and "codepointHex"
})
.pipe(gulp.dest('www/font/'));
});
Every icon must be prefixed with it's codepoint. The appendCodepoints
option
allows to do it automatically. Then, in your own CSS, you just have to use
the corresponding codepoint to display your icon. See this
sample less mixin
for a real world usage.
The plugin stream emits a codepoints
event letting you do whatever you want
with them.
Please report icons to font issues to the svgicons2svgfont
repository on wich
this plugin depends.
Type: String
Default value: 'iconfont'
A string value that is used to name your font-family (required).
Type: Boolean
Default value: false
Creates a monospace font of the width of the largest input icon.
Type: Number
The ouputted font height (defaults to the height of the highest input icon).
Type: Number
Default value: 0
The font descent. It is usefull to fix the font baseline yourself.
The ascent formula is : ascent = fontHeight - descent.
Type: Boolean
Default value: false
Allow to append codepoints to icon files in order to always keep the same codepoints.
Type: Boolean
Default value: false
Set to true to also convert read icons that doesn't have the .svg extension.