美文网首页
html载入svg雪碧图

html载入svg雪碧图

作者: 吞风咽雪 | 来源:发表于2020-08-14 10: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>
    
    

    相关文章

      网友评论

          本文标题:html载入svg雪碧图

          本文链接:https://www.haomeiwen.com/subject/cotgdktx.html