html载入svg雪碧图
2020-08-14 本文已影响0人
吞风咽雪
gulpfile.js
var gulp = require('gulp');
var path = require('path');
var svgSymbols = require('gulp-svg-symbols');
gulp.task('build', function() {
return gulp.src('svgs/*.svg').pipe(
svgSymbols({
svgAttrs: {
style: 'position: absolute; width: 0px; height: 0px; overflow: hidden;'
},
slug: name => 'icon-' + name,
templates: [
path.join(__dirname, `template/svg-symbols.tpl`),
]
})
).pipe(
gulp.dest('dist')
);
})
template
<svg<%= attributesToString(svgAttrs) %>>
<% if (defs) { %><defs>
<%= defs.trim() %>
</defs>
<% } %><%= icons.map(svgdataToSymbol).join('\n') %>
</svg>