Gruntfile.js
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
less: {
dist: {
files: [{
expand: true,
cwd: 'css/style',
src: ['*.less'],
dest: 'css/style',
ext: '.css'
}]
}
},
sprite:{
all: {
// 待合并的文件
src : 'images/src/*.png',
// 合并后输出的文件
dest : 'images/dist/sprite.png',
// 输出对应雪碧图的样式
destCss : 'css/style/m2.0/sprite.less',
// 可选: 手动指定样式里引用图片的路径
imgPath : '../../images/dist/sprite.png',
cssVarMap: function(sprite) {
sprite.name = sprite.name.replace(/^\s{1}/, ''); //去除文件名前空白
sprite.name = sprite.name.replace('@2x', '');
sprite.name = sprite.name.replace(/^\d\./, '');
sprite.name = sprite.name.toLowerCase();
sprite.name = 'icon-' + sprite.name;
},
// 可选: 指定算法 (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'
}
},
watch: {
options: {
nospawn: true
},
css: {
files: [
'css/style/*.less'
],
tasks: ['less'],
options: {
livereload: true
}
}
}
});
grunt.loadNpmTasks( "grunt-contrib-less" );
grunt.loadNpmTasks( "grunt-contrib-watch" );
grunt.loadNpmTasks('grunt-spritesmith');
grunt.registerTask('default', [
'sprite'
]);
};