2016-11-10 02:31:39 +08:00
|
|
|
|
/**
|
2016-10-14 16:23:52 +08:00
|
|
|
|
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');
|
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
//获取参数
|
2016-10-14 16:23:52 +08:00
|
|
|
|
var argv = require('minimist')(process.argv.slice(2), {
|
|
|
|
|
default: {
|
|
|
|
|
ver: 'all'
|
|
|
|
|
}
|
2016-11-30 02:23:57 +08:00
|
|
|
|
})
|
2016-10-14 16:23:52 +08:00
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
//注释
|
|
|
|
|
,note = [
|
2017-02-21 06:48:54 +08:00
|
|
|
|
'/** <%= pkg.name %>-v<%= pkg.version %> <%= pkg.license %> License By <%= pkg.homepage %> */\n <%= js %>'
|
2016-11-30 15:48:30 +08:00
|
|
|
|
,{pkg: pkg, js: ';'}
|
2016-11-30 02:23:57 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
//模块
|
|
|
|
|
,mods = 'laytpl,laypage,laydate,jquery,layer,element,upload,form,tree,util,flow,layedit,code'
|
|
|
|
|
|
|
|
|
|
//任务
|
|
|
|
|
,task = {
|
2017-02-21 06:48:54 +08:00
|
|
|
|
|
|
|
|
|
//压缩js模块
|
2016-11-30 02:23:57 +08:00
|
|
|
|
minjs: function(ver) {
|
2017-02-21 06:48:54 +08:00
|
|
|
|
ver = ver === 'open' || argv.open;
|
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
//可指定模块压缩,eg:gulp minjs --mod layer,laytpl
|
2016-10-14 16:23:52 +08:00
|
|
|
|
var mod = argv.mod ? function(){
|
|
|
|
|
return '(' + argv.mod.replace(/,/g, '|') + ')';
|
2016-11-30 02:23:57 +08:00
|
|
|
|
}() : ''
|
|
|
|
|
,src = [
|
2016-10-14 16:23:52 +08:00
|
|
|
|
'./src/**/*'+ mod +'.js'
|
2017-02-21 06:48:54 +08:00
|
|
|
|
,'!./src/**/mobile/*.js'
|
|
|
|
|
,'!./src/lay/**/mobile.js'
|
2016-10-14 18:22:51 +08:00
|
|
|
|
,'!./src/lay/all.js'
|
2017-02-21 06:48:54 +08:00
|
|
|
|
,'!./src/lay/all-mobile.js'
|
2016-11-30 02:23:57 +08:00
|
|
|
|
]
|
2017-02-21 06:48:54 +08:00
|
|
|
|
,dir = ver ? 'release' : 'build';
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
|
|
|
|
//过滤 layim
|
2017-02-21 06:48:54 +08:00
|
|
|
|
if(ver){
|
2016-11-30 02:23:57 +08:00
|
|
|
|
src.push('!./src/lay/**/layim.js');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gulp.src(src).pipe(uglify())
|
|
|
|
|
.pipe(header.apply(null, note))
|
|
|
|
|
.pipe(gulp.dest('./'+ dir));
|
2016-10-14 16:23:52 +08:00
|
|
|
|
|
|
|
|
|
}
|
2017-02-21 06:48:54 +08:00
|
|
|
|
|
|
|
|
|
//打包PC合并版JS,即包含layui.js和所有模块的合并
|
2016-11-30 02:23:57 +08:00
|
|
|
|
,alljs: function(ver){
|
2017-02-21 06:48:54 +08:00
|
|
|
|
ver = ver === 'open' || argv.open;
|
|
|
|
|
|
|
|
|
|
var src = [
|
|
|
|
|
'./src/**/{layui,all,'+ mods +'}.js'
|
|
|
|
|
,'!./src/**/mobile/*.js'
|
|
|
|
|
]
|
|
|
|
|
,dir = ver ? 'release' : 'build';
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
|
|
|
|
return gulp.src(src).pipe(uglify())
|
|
|
|
|
.pipe(concat('layui.all.js', {newLine: ''}))
|
|
|
|
|
.pipe(header.apply(null, note))
|
|
|
|
|
.pipe(gulp.dest('./'+ dir +'/lay/dest/'));
|
2016-10-14 16:23:52 +08:00
|
|
|
|
}
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
|
//打包mobile模块集合
|
|
|
|
|
,mobile: function(ver){
|
|
|
|
|
ver = ver === 'open' || argv.open;
|
|
|
|
|
|
|
|
|
|
var mods = 'layer-mobile,zepto,upload-mobile', src = [
|
|
|
|
|
'./src/lay/all-mobile.js'
|
|
|
|
|
,'./src/lay/modules/laytpl.js'
|
|
|
|
|
,'./src/**/mobile/{'+ mods +'}.js'
|
|
|
|
|
]
|
|
|
|
|
,dir = ver ? 'release' : 'build';
|
|
|
|
|
|
|
|
|
|
if(ver){
|
|
|
|
|
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文件
|
2016-11-30 02:23:57 +08:00
|
|
|
|
,mincss: function(ver){
|
2017-02-21 06:48:54 +08:00
|
|
|
|
ver = ver === 'open' || argv.open;
|
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
var src = ['./src/css/**/*.css']
|
2017-02-21 06:48:54 +08:00
|
|
|
|
,dir = ver ? 'release' : 'build'
|
2016-11-30 15:48:30 +08:00
|
|
|
|
,noteNew = JSON.parse(JSON.stringify(note));
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
|
if(ver){
|
2016-11-30 02:23:57 +08:00
|
|
|
|
src.push('!./src/css/**/layim.css');
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 15:48:30 +08:00
|
|
|
|
noteNew[1].js = '';
|
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
return gulp.src(src).pipe(minify({
|
2016-10-14 16:23:52 +08:00
|
|
|
|
compatibility: 'ie7'
|
2016-11-30 15:48:30 +08:00
|
|
|
|
})).pipe(header.apply(null, noteNew))
|
2016-11-30 02:23:57 +08:00
|
|
|
|
.pipe(gulp.dest('./'+ dir +'/css'));
|
2016-10-14 16:23:52 +08:00
|
|
|
|
}
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
|
//复制iconfont文件
|
2016-11-30 02:23:57 +08:00
|
|
|
|
,font: function(ver){
|
2017-02-21 06:48:54 +08:00
|
|
|
|
ver = ver === 'open' || argv.open;
|
|
|
|
|
|
|
|
|
|
var dir = ver ? 'release' : 'build';
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
2016-10-14 16:23:52 +08:00
|
|
|
|
return gulp.src('./src/font/*')
|
|
|
|
|
.pipe(rename({}))
|
2016-11-30 02:23:57 +08:00
|
|
|
|
.pipe(gulp.dest('./'+ dir +'/font'));
|
2016-10-14 16:23:52 +08:00
|
|
|
|
}
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
|
//复制组件可能所需的非css和js资源
|
|
|
|
|
,mv: function(ver){
|
|
|
|
|
ver = ver === 'open' || argv.open;
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
|
var src = ['./src/**/*.{png,jpg,gif,html,mp3,json}']
|
|
|
|
|
,dir = ver ? 'release' : 'build';
|
|
|
|
|
|
|
|
|
|
if(ver){
|
2016-11-30 02:23:57 +08:00
|
|
|
|
src.push('!./src/**/layim/**/*.*');
|
|
|
|
|
}
|
2016-10-14 16:23:52 +08:00
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
gulp.src(src).pipe(rename({}))
|
|
|
|
|
.pipe(gulp.dest('./'+ dir));
|
2016-10-14 16:23:52 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//清理
|
|
|
|
|
gulp.task('clear', function(cb) {
|
|
|
|
|
return del(['./build/*'], cb);
|
|
|
|
|
});
|
2016-11-30 02:23:57 +08:00
|
|
|
|
gulp.task('clearRelease', function(cb) {
|
|
|
|
|
return del(['./release/*'], cb);
|
|
|
|
|
});
|
2016-11-10 02:31:39 +08:00
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
|
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);
|
2016-10-14 16:23:52 +08:00
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
//开源版
|
|
|
|
|
gulp.task('default', ['clearRelease'], function(){
|
|
|
|
|
for(var key in task){
|
|
|
|
|
task[key]('open');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-14 16:23:52 +08:00
|
|
|
|
//完整任务
|
2016-11-30 02:23:57 +08:00
|
|
|
|
gulp.task('all', ['clear'], function(){
|
2016-10-14 16:23:52 +08:00
|
|
|
|
for(var key in task){
|
|
|
|
|
task[key]();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-30 02:23:57 +08:00
|
|
|
|
|
2016-10-14 16:23:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|