-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
174 lines (169 loc) · 4.84 KB
/
Gruntfile.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
module.exports = function(grunt) {
var task = grunt.task;
var SRC = 'src/';
grunt.initConfig({
// 配置文件,参考package.json配置方式,必须设置项是
// name, version, author
// name作为gallery发布后的模块名
// version是版本,也是发布目录
// author必须是{name: "xxx", email: "xxx"}格式
pkg: grunt.file.readJSON('package.json'),
banner: '/*!build time : <%= grunt.template.today("yyyy-mm-dd h:MM:ss TT") %>*/\n',
// 对build目录进行清理
clean: {
build: {
src: './build/*'
}
},
// kmc打包任务,默认情况,入口文件是index.js,可以自行添加入口文件,在files下面
// 添加
kmc: {
options: {
packages: [
{
name: '<%= pkg.name %>',
path: '../'
}
],
depFilePath: 'mods.js',
fixModuleName:true,
map: [["<%= pkg.name %>/src/", "kg/<%= pkg.name %>/<%= pkg.version %>/"]]
},
main: {
files: [
{
expand: true,
cwd: SRC,
src: [ './*.js','./plugin/*.js' ],
dest: 'build/'
}
]
}
},
/**
* 对JS文件进行压缩
* @link https://github.com/gruntjs/grunt-contrib-uglify
*/
uglify: {
options: {
compress:{
global_defs:{"DEBUG":false},
drop_console:true,
dead_code:true
},
banner: '<%= banner %>',
beautify: {
ascii_only: true
}
},
page: {
files: [
{
expand: true,
cwd: './build',
src: ['**/*.js', '!**/*-min.js'],
dest: './build',
ext: '-min.js'
}
]
}
},
less: {
options: {
paths: './'
},
main: {
files: [
{
expand: true,
cwd:SRC,
src: ['**/*.less',
'!build/**/*.less',
'!demo/**/*.less'],
dest: './build/',
ext: '.less.css'
}
]
}
},
// 拷贝 CSS 文件
copy : {
main: {
files:[
{
expand:true,
cwd:SRC,
src: [
'**/*.css',
'!build/**/*.css',
'!demo/**/*.css'
],
dest: './build/',
filter: 'isFile'
}
]
}
},
// 监听JS、CSS、LESS文件的修改
watch: {
'all': {
files: [
'./src/**/*.css',
'!./build/**/*'
],
tasks: [ 'build' ]
}
},
cssmin: {
scss: {
files: [
{
expand: true,
cwd: './build',
src: ['**/*.scss.css', '!**/*.scss-min.css'],
dest: './build',
ext: '.scss-min.css'
}
]
},
less: {
files: [
{
expand: true,
cwd: './build',
src: ['**/*.less.css', '!**/*.less-min.css'],
dest: './build',
ext: '.less-min.css'
}
]
},
main: {
files: [
{
expand: true,
cwd: './build',
src: ['**/*.css', '!**/*-min.css','!**/*.less.css','!**/*.scss.css'],
dest: './build',
ext: '-min.css'
}
]
}
}
});
// 使用到的任务,可以增加其他任务
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-kmc');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('build', '默认构建任务', function() {
task.run(['clean:build', 'kmc','uglify', 'copy','less','cssmin']);
});
return grunt.registerTask('default', '',function(type){
if (!type) {
task.run(['build']);
}
});
};