gulpfile.js
1.09 KB
var gulp = require('gulp');
var spritesmith = require('gulp.spritesmith');
gulp.task('sprite', function() {
var spriteData = gulp.src('src/*.png').pipe(spritesmith({
imgName: 'sprite.png',
// cssName: 'sprite.less',
// 输出对应雪碧图的样式
destCss: '../../2.3.0/sp-sprite.less',
imgPath: '../images/2.3.0/dist/sprite.png',
cssVarMap: function(sprite) {
sprite.name = sprite.name.replace(/^\s{1}/, ''); //去除文件名前空白
//sprite.name = sprite.name.replace('@2x', '');
sprite.name = 'icon-' + sprite.name;
sprite.name = sprite.name;
},
padding: 6,
// 可选: 指定算法 (top-down, left-right, diagonal,alt-diagonal, binary-tree )等
// 默认是top-down,二叉树合并出来的图体积最小
algorithm: 'binary-tree',
// 可选: 指定CSS格式 (默认根据destCSS中的后缀设置格式)
// (stylus, scss, scss_maps, sass, less, json, json_array, css)
cssFormat: 'less'
}));
return spriteData.pipe(gulp.dest('dest'));
});