diff --git a/index.js b/index.js index 1b44708..75cda8d 100644 --- a/index.js +++ b/index.js @@ -18,12 +18,15 @@ function iconfontCSS(config) { engine, cssClass; + var availableFormats = ['eot', 'woff2', 'woff', 'ttf', 'svg']; + // Set default values config = _.merge({ path: 'css', targetPath: '_icons.css', fontPath: './', engine: 'lodash', + formats: availableFormats, firstGlyph: 0xE001, fixedCodepoints: false, cssClass: 'icon' @@ -100,13 +103,42 @@ function iconfontCSS(config) { }; stream._flush = function(cb) { - var content; + var content, + formatTypes = [], + formatModifiers = { + 'eot': { extension : "eot?#iefix" }, + 'ttf': { format : 'truetype' }, + 'svg': { extension : 'svg#'+config.fontName } + }; + + config.formats = _.intersection(availableFormats, config.formats); + + _.each(config.formats, function(format) { + var ext = formatModifiers[format] && formatModifiers[format]["extension"] + ? formatModifiers[format]["extension"] + : format; + + var format = formatModifiers[format] && formatModifiers[format]["format"] + ? formatModifiers[format]["format"] + : format; + + formatTypes.push({ + 'url': config.fontPath + config.fontName + "." + ext, + 'format' : format + }); + }); + + formatTypes = _.map(formatTypes, function(type) { + return "url('"+type.url+"') format('"+type.format+"')" + }); + if (glyphMap.length) { consolidate[config.engine](config.path, { glyphs: glyphMap, fontName: config.fontName, fontPath: config.fontPath, - cssClass: config.cssClass + cssClass: config.cssClass, + formatTypes: formatTypes }, function(err, html) { if (err) { throw new gutil.PluginError(PLUGIN_NAME, 'Error in template: ' + err.message); diff --git a/package.json b/package.json index ef7d2db..de1afe9 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "gulp-iconfont-css", + "name": "gulp-iconfont-css-fork", "version": "2.1.0", "description": "Generate (S)CSS file for icon font created with Gulp", "license": "MIT", diff --git a/templates/_icons.css b/templates/_icons.css index 848d4ff..134d3b2 100644 --- a/templates/_icons.css +++ b/templates/_icons.css @@ -1,11 +1,10 @@ + @font-face { font-family: "<%= fontName %>"; src: url('<%= fontPath %><%= fontName %>.eot'); - src: url('<%= fontPath %><%= fontName %>.eot?#iefix') format('eot'), - url('<%= fontPath %><%= fontName %>.woff2') format('woff2'), - url('<%= fontPath %><%= fontName %>.woff') format('woff'), - url('<%= fontPath %><%= fontName %>.ttf') format('truetype'), - url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg'); + <% if(formatTypes.length) {%> + src: <%= formatTypes.join(", ")%>; + <% } %> } .<%= cssClass %>:before { diff --git a/templates/_icons.less b/templates/_icons.less index 9a21d18..5f07a6f 100644 --- a/templates/_icons.less +++ b/templates/_icons.less @@ -1,11 +1,9 @@ @font-face { font-family: "<%= fontName %>"; src: url('<%= fontPath %><%= fontName %>.eot'); - src: url('<%= fontPath %><%= fontName %>.eot?#iefix') format('eot'), - url('<%= fontPath %><%= fontName %>.woff2') format('woff2'), - url('<%= fontPath %><%= fontName %>.woff') format('woff'), - url('<%= fontPath %><%= fontName %>.ttf') format('truetype'), - url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg'); + <% if(formatTypes.length) {%> + src: <%= formatTypes.join(", ")%>; + <% } %> } .<%= cssClass%>-base-pseudo { diff --git a/templates/_icons.scss b/templates/_icons.scss index 1a05d83..ed42418 100644 --- a/templates/_icons.scss +++ b/templates/_icons.scss @@ -1,11 +1,9 @@ @font-face { font-family: "<%= fontName %>"; src: url('<%= fontPath %><%= fontName %>.eot'); - src: url('<%= fontPath %><%= fontName %>.eot?#iefix') format('eot'), - url('<%= fontPath %><%= fontName %>.woff2') format('woff2'), - url('<%= fontPath %><%= fontName %>.woff') format('woff'), - url('<%= fontPath %><%= fontName %>.ttf') format('truetype'), - url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg'); + <% if(formatTypes.length) {%> + src: <%= formatTypes.join(", ")%>; + <% } %> } @mixin <%= cssClass%>-styles {