forked from layui/layui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (99 loc) · 3.26 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
/**
layui构建
*/
var pkg = require('./package.json');
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 argv = require('minimist')(process.argv.slice(2), {
default: {
ver: 'all'
}
}), mods = 'laytpl,laypage,laydate,jquery,layer,element,upload,form,tree,util,flow,layedit,code';
var task = {
minjs: function() {
//可指定模块压缩
var mod = argv.mod ? function(){
return '(' + argv.mod.replace(/,/g, '|') + ')';
}() : '';
return gulp.src([
'./src/**/*'+ mod +'.js'
,'!./src/lay/all.js'
,'!./src/lay/mod.js'
]).pipe(uglify())
.pipe(header('/** <%= pkg.name %>-v<%= pkg.version %> <%= pkg.license %> license By <%= pkg.homepage %> */\n ;', {pkg: pkg}))
.pipe(gulp.dest('./build'))
}
,modjs: function(){
return gulp.src([
,'./src/lay/**/{mod,'+ mods +'}.js'
,'!./src/lay/**/layim.js' //LayIM需授权
,'!./src/lay/**/mobile/*.js'
]).pipe(uglify())
.pipe(concat('layui.mod.js', {newLine: ''}))
.pipe(header('/** <%= pkg.name %>-v<%= pkg.version %>(All Modules) <%= pkg.license %> license By <%= pkg.homepage %> */\n ;', {pkg: pkg}))
.pipe(gulp.dest('./build/lay/dest/'));
}
,alljs: function(){
return gulp.src([
,'./src/**/{layui,all,'+ mods +'}.js'
,'!./src/lay/modules/layim.js' //LayIM需授权
,'!./src/lay/modules/mobile/*.js'
]).pipe(uglify())
.pipe(concat('layui.all.js', {newLine: ''}))
.pipe(header('/** <%= pkg.name %>-v<%= pkg.version %> <%= pkg.license %> license By <%= pkg.homepage %> */\n ;', {pkg: pkg}))
.pipe(gulp.dest('./build/lay/dest/'));
}
,mincss: function() {
return gulp.src('./src/css/**/*.css')
.pipe(minify({
compatibility: 'ie7'
}))
.pipe(header('/** <%= pkg.name %>-v<%= pkg.version %> <%= pkg.license %> license By <%= pkg.homepage %> */\n', {pkg : pkg} ))
.pipe(gulp.dest('./build/css'));
}
,font: function() {
return gulp.src('./src/font/*')
.pipe(rename({}))
.pipe(gulp.dest('./build/font'));
}
,images: function(){
gulp.src([
'./src/css/**/*.png'
,'./src/css/**/*.jpg'
,'./src/css/**/*.gif'
]).pipe(rename({}))
.pipe(gulp.dest('./build/css'));
return gulp.src([
'./src/images/**/*.png'
,'./src/images/**/*.jpg'
,'./src/images/**/*.gif'
]).pipe(rename({}))
.pipe(gulp.dest('./build/images'));
}
};
//清理
gulp.task('clear', function(cb) {
return del(['./build/*'], cb);
});
gulp.task('minjs', task.minjs); //压缩js模块
gulp.task('modjs', task.modjs); //打包PC完整模块,即各模块的合并
gulp.task('alljs', task.alljs); //打包PC合并版,即包含layui.js和所有模块的合并
gulp.task('mincss', task.mincss); //压缩css文件
gulp.task('font', task.font); //复制iconfont文件
gulp.task('images', task.images); //复制组件可能所需的图片
//完整任务
gulp.task('default', ['clear'], function(){
for(var key in task){
task[key]();
}
});
//开源版
gulp.task('open', ['clear'], function(){
});