UNPKG

1.1 kBJavaScriptView Raw
1'use strict';
2var through = require('through2');
3
4module.exports = function (config) {
5 config = Object.assign({ fontName: 'iconfont', 'type': 'woff' }, config)
6 // create a stream through which each file will pass
7 return through.obj(function (file, enc, callback) {
8
9 if (file.isNull()) {
10 this.push(file);
11 // do nothing if no contents
12 return callback();
13 }
14
15 if (file.isStream()) {
16 console.error('Streaming not supported')
17 this.emit('error', 'font64:Streaming not supported');
18 return callback();
19 }
20
21 if (file.isBuffer()) {
22 var file64 = new Buffer(file.contents).toString('base64');
23 var csswrapper = '@font-face {font-family: ' + config.fontName + '; src: url(data:' + config.type + ';base64,' + file64 + ');}';
24 var output = csswrapper;
25
26 file.contents = new Buffer(output);
27 file.path = gutil.replaceExtension(file.path, '.css');
28 return callback(null, file);
29 }
30 });
31};