forked from layui/layui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
245 lines (190 loc) · 5.56 KB
/
gulpfile.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
layui构建
*/
var pkg = require('./package.json');
var inds = pkg.independents;
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var minify = require('gulp-minify-css');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var header = require('gulp-header');
var del = require('del');
var gulpif = require('gulp-if');
var minimist = require('minimist');
var zip = require('gulp-zip');
//获取参数
var argv = require('minimist')(process.argv.slice(2), {
default: {
ver: 'all'
}
})
//注释
,note = [
'/** <%= pkg.realname %>-v<%= pkg.version %> <%= pkg.license %> License By <%= pkg.homepage %> */\n <%= js %>'
,{pkg: pkg, js: ';'}
]
//模块
,mods = 'laytpl,laypage,laydate,jquery,layer,element,upload,slider,colorpicker,form,tree,table,carousel,rate,util,flow,layedit,code'
//发行版本目录
,releaseDir = './release/zip/layui-v' + pkg.version
,release = releaseDir + '/layui'
//目标木
,destDir = function(ver){
return ver ? release : function(){
return argv.rc ? 'rc' : 'dist'
}();
}
//任务
,task = {
//压缩js模块
minjs: function(ver) {
ver = ver === 'open';
//可指定模块压缩,eg:gulp minjs --mod layer,laytpl
var mod = argv.mod ? function(){
return '(' + argv.mod.replace(/,/g, '|') + ')';
}() : ''
,src = [
'./src/**/*'+ mod +'.js'
,'!./src/**/mobile/*.js'
,'!./src/lay/**/mobile.js'
,'!./src/lay/all.js'
,'!./src/lay/all-mobile.js'
]
,dir = destDir(ver);
//过滤 layim
if(ver || argv.open){
src.push('!./src/lay/**/layim.js');
}
return gulp.src(src).pipe(uglify())
.pipe(header.apply(null, note))
.pipe(gulp.dest('./'+ dir));
}
//打包PC合并版JS,即包含layui.js和所有模块的合并
,alljs: function(ver){
ver = ver === 'open';
var src = [
'./src/**/{layui,all,'+ mods +'}.js'
,'!./src/**/mobile/*.js'
]
,dir = destDir(ver);
return gulp.src(src).pipe(uglify())
.pipe(concat('layui.all.js', {newLine: ''}))
.pipe(header.apply(null, note))
.pipe(gulp.dest('./'+ dir));
}
//打包mobile模块集合
,mobile: function(ver){
ver = ver === 'open';
var mods = 'layer-mobile,zepto,upload-mobile', src = [
'./src/lay/all-mobile.js'
,'./src/lay/modules/laytpl.js'
,'./src/**/mobile/{'+ mods +'}.js'
]
,dir = destDir(ver);
if(ver || argv.open){
src.push('./src/**/mobile/layim-mobile-open.js');
}
src.push((ver ? '!' : '') + './src/**/mobile/layim-mobile.js');
src.push('./src/lay/modules/mobile.js');
return gulp.src(src).pipe(uglify())
.pipe(concat('mobile.js', {newLine: ''}))
.pipe(header.apply(null, note))
.pipe(gulp.dest('./'+ dir + '/lay/modules/'));
}
//压缩css文件
,mincss: function(ver){
ver = ver === 'open';
var src = [
'./src/css/**/*.css'
,'!./src/css/**/font.css'
]
,dir = destDir(ver)
,noteNew = JSON.parse(JSON.stringify(note));
if(ver || argv.open){
src.push('!./src/css/**/layim.css');
}
noteNew[1].js = '';
return gulp.src(src).pipe(minify({
compatibility: 'ie7'
})).pipe(header.apply(null, noteNew))
.pipe(gulp.dest('./'+ dir +'/css'));
}
//复制iconfont文件
,font: function(ver){
ver = ver === 'open';
var dir = destDir(ver);
return gulp.src('./src/font/*')
.pipe(rename({}))
.pipe(gulp.dest('./'+ dir +'/font'));
}
//复制组件可能所需的非css和js资源
,mv: function(ver){
ver = ver === 'open';
var src = ['./src/**/*.{png,jpg,gif,html,mp3,json}']
,dir = destDir(ver);
if(ver || argv.open){
src.push('!./src/**/layim/**/*.*');
}
gulp.src(src).pipe(rename({}))
.pipe(gulp.dest('./'+ dir));
}
//复制发行的引导文件
,release: function(){
gulp.src('./release/doc/**/*')
.pipe(gulp.dest(releaseDir));
}
};
//清理
gulp.task('clear', function(cb) {
return del(['./'+ (argv.rc ? 'rc' : 'dist') +'/*'], cb);
});
gulp.task('clearRelease', function(cb) {
return del([releaseDir], cb);
});
gulp.task('minjs', task.minjs);
gulp.task('alljs', task.alljs);
gulp.task('mobile', task.mobile);
gulp.task('mincss', task.mincss);
gulp.task('font', task.font);
gulp.task('mv', task.mv);
gulp.task('release', task.release);
//发行版 gulp
gulp.task('default', ['clearRelease'], function(){
for(var key in task){
task[key]('open');
}
});
//完整任务 gulp all
gulp.task('all', ['clear'], function(){ //过滤 layim:gulp all --open、rc 版:gulp all --rc
for(var key in task){
task[key]();
}
});
//打包 layer 独立版
gulp.task('layer', function(){
var dir = './release/layer';
gulp.src('./src/css/modules/layer/default/*')
.pipe(gulp.dest(dir + '/src/theme/default'));
return gulp.src('./src/lay/modules/layer.js')
.pipe(gulp.dest(dir + '/src'));
});
//打包 layDate 独立版
gulp.task('laydate', function(){
var dir = './release/laydate';
gulp.src('./src/css/modules/laydate/default/{font,laydate}.css')
.pipe(concat('laydate.css', {newLine: '\n\n'}))
.pipe(gulp.dest(dir + '/src/theme/default'));
return gulp.src('./src/lay/modules/laydate.js')
.pipe(gulp.dest(dir + '/src'));
});
//打包 LayIM 版本
gulp.task('layim', function(){
var dir = './release/zip/layim-v'+ inds.layim;
gulp.src('./release/doc-layim/**/*')
.pipe(gulp.dest(dir))
gulp.src('./src/**/*')
.pipe(gulp.dest(dir + '/src'))
return gulp.src('./dist/**/*')
.pipe(gulp.dest(dir + '/dist'));
});