安装
npm install grunt-spritesmith --save-dev
module.exports = function (grunt) {
// Configure grunt
grunt.initConfig({
sprite:{
all: {
src: 'path/to/your/sprites/*.png',素材图片
dest: 'destination/of/spritesheet.png',// 默认雪碧图输出路径
destCss: 'destination/of/sprites.css' 雪碧图less输出路径,也支持输出css
}
}
});
// Load in `grunt-spritesmith`
grunt.loadNpmTasks('grunt-spritesmith');
};
运行
$ grunt sprite
npm 官网 https://www.npmjs.com/package/grunt-spritesmith