2021-03-31 14:07:23 +08:00
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
/**
|
2021-03-31 14:07:23 +08:00
|
|
|
|
layui Build
|
2017-08-21 08:51:13 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var pkg = require('./package.json');
|
2017-09-15 00:50:23 +08:00
|
|
|
|
var inds = pkg.independents;
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
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');
|
2021-03-31 14:07:23 +08:00
|
|
|
|
var replace = require('gulp-replace');
|
2017-08-21 08:51:13 +08:00
|
|
|
|
var header = require('gulp-header');
|
|
|
|
|
var del = require('del');
|
|
|
|
|
var gulpif = require('gulp-if');
|
|
|
|
|
var minimist = require('minimist');
|
2017-08-24 20:26:48 +08:00
|
|
|
|
var zip = require('gulp-zip');
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
//获取参数
|
|
|
|
|
var argv = require('minimist')(process.argv.slice(2), {
|
|
|
|
|
default: {
|
|
|
|
|
ver: 'all'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
//注释
|
|
|
|
|
,note = [
|
2021-03-31 14:07:23 +08:00
|
|
|
|
'/** <%= pkg.realname %> v<%= pkg.version %> | Released under the <%= pkg.license %> license */\n <%= js %>'
|
2017-08-21 08:51:13 +08:00
|
|
|
|
,{pkg: pkg, js: ';'}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
//模块
|
2021-03-31 14:07:23 +08:00
|
|
|
|
,mods = 'lay,laytpl,laypage,laydate,jquery,layer,util,element,upload,dropdown,slider,colorpicker,form,tree,transfer,table,carousel,rate,flow,layedit,code'
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2017-08-24 20:26:48 +08:00
|
|
|
|
//发行版本目录
|
2017-09-03 08:25:54 +08:00
|
|
|
|
,releaseDir = './release/zip/layui-v' + pkg.version
|
2017-08-24 20:26:48 +08:00
|
|
|
|
,release = releaseDir + '/layui'
|
|
|
|
|
|
2018-04-03 05:07:35 +08:00
|
|
|
|
//目标木
|
|
|
|
|
,destDir = function(ver){
|
|
|
|
|
return ver ? release : function(){
|
|
|
|
|
return argv.rc ? 'rc' : 'dist'
|
|
|
|
|
}();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
//任务
|
|
|
|
|
,task = {
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//聚合 JS 文件
|
|
|
|
|
alljs: function(ver){
|
2017-08-21 08:51:13 +08:00
|
|
|
|
var src = [
|
2021-04-05 23:41:30 +08:00
|
|
|
|
'./src/**/{layui,layui.all,'+ mods +'}.js'
|
2017-08-21 08:51:13 +08:00
|
|
|
|
]
|
2018-04-03 05:07:35 +08:00
|
|
|
|
,dir = destDir(ver);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
return gulp.src(src).pipe(uglify())
|
2021-03-31 14:07:23 +08:00
|
|
|
|
.pipe(concat('layui.js', {newLine: ''}))
|
2017-08-21 08:51:13 +08:00
|
|
|
|
.pipe(header.apply(null, note))
|
|
|
|
|
.pipe(gulp.dest('./'+ dir));
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//压缩 css 文件
|
2017-08-21 08:51:13 +08:00
|
|
|
|
,mincss: function(ver){
|
2017-09-13 16:06:55 +08:00
|
|
|
|
var src = [
|
|
|
|
|
'./src/css/**/*.css'
|
|
|
|
|
,'!./src/css/**/font.css'
|
|
|
|
|
]
|
2018-04-03 05:07:35 +08:00
|
|
|
|
,dir = destDir(ver)
|
2017-08-21 08:51:13 +08:00
|
|
|
|
,noteNew = JSON.parse(JSON.stringify(note));
|
|
|
|
|
|
|
|
|
|
noteNew[1].js = '';
|
|
|
|
|
|
|
|
|
|
return gulp.src(src).pipe(minify({
|
|
|
|
|
compatibility: 'ie7'
|
2021-03-31 17:36:19 +08:00
|
|
|
|
})) //.pipe(header.apply(null, noteNew))
|
2017-08-21 08:51:13 +08:00
|
|
|
|
.pipe(gulp.dest('./'+ dir +'/css'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//复制iconfont文件
|
|
|
|
|
,font: function(ver){
|
2018-04-03 05:07:35 +08:00
|
|
|
|
var dir = destDir(ver);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
return gulp.src('./src/font/*')
|
|
|
|
|
.pipe(rename({}))
|
|
|
|
|
.pipe(gulp.dest('./'+ dir +'/font'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//复制组件可能所需的非css和js资源
|
|
|
|
|
,mv: function(ver){
|
|
|
|
|
var src = ['./src/**/*.{png,jpg,gif,html,mp3,json}']
|
2018-04-03 05:07:35 +08:00
|
|
|
|
,dir = destDir(ver);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
gulp.src(src).pipe(rename({}))
|
|
|
|
|
.pipe(gulp.dest('./'+ dir));
|
|
|
|
|
}
|
2017-08-24 20:26:48 +08:00
|
|
|
|
|
|
|
|
|
//复制发行的引导文件
|
|
|
|
|
,release: function(){
|
|
|
|
|
gulp.src('./release/doc/**/*')
|
2021-03-31 14:07:23 +08:00
|
|
|
|
.pipe(replace('http://local.res.layui.com/layui/dist/', 'layui/'))
|
2017-08-24 20:26:48 +08:00
|
|
|
|
.pipe(gulp.dest(releaseDir));
|
|
|
|
|
}
|
2017-08-21 08:51:13 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//清理
|
|
|
|
|
gulp.task('clear', function(cb) {
|
2018-04-03 05:07:35 +08:00
|
|
|
|
return del(['./'+ (argv.rc ? 'rc' : 'dist') +'/*'], cb);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
});
|
|
|
|
|
gulp.task('clearRelease', function(cb) {
|
2017-08-24 20:26:48 +08:00
|
|
|
|
return del([releaseDir], cb);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('alljs', task.alljs);
|
|
|
|
|
gulp.task('mincss', task.mincss);
|
|
|
|
|
gulp.task('font', task.font);
|
|
|
|
|
gulp.task('mv', task.mv);
|
2017-08-24 20:26:48 +08:00
|
|
|
|
gulp.task('release', task.release);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//完整任务 gulp
|
|
|
|
|
gulp.task('default', ['clear'], function(){ //rc 版:gulp --rc
|
2017-08-21 08:51:13 +08:00
|
|
|
|
for(var key in task){
|
2021-03-31 14:07:23 +08:00
|
|
|
|
task[key]();
|
2017-08-21 08:51:13 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//发行版 gulp rls
|
|
|
|
|
gulp.task('rls', ['clearRelease'], function(){ // gulp rls
|
2017-09-13 16:06:55 +08:00
|
|
|
|
for(var key in task){
|
2021-03-31 14:07:23 +08:00
|
|
|
|
task[key]('release');
|
2017-09-13 16:06:55 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-07 15:51:12 +08:00
|
|
|
|
//打包 layer 独立版
|
2017-09-13 16:06:55 +08:00
|
|
|
|
gulp.task('layer', function(){
|
|
|
|
|
var dir = './release/layer';
|
|
|
|
|
|
|
|
|
|
gulp.src('./src/css/modules/layer/default/*')
|
|
|
|
|
.pipe(gulp.dest(dir + '/src/theme/default'));
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
return gulp.src('./src/modules/layer.js')
|
2017-09-13 16:06:55 +08:00
|
|
|
|
.pipe(gulp.dest(dir + '/src'));
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
|
2017-12-07 15:51:12 +08:00
|
|
|
|
//打包 layDate 独立版
|
2017-09-13 16:06:55 +08:00
|
|
|
|
gulp.task('laydate', function(){
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//发行目录
|
|
|
|
|
var dir = './release/laydate'
|
|
|
|
|
|
|
|
|
|
//注释
|
|
|
|
|
,notes = [
|
|
|
|
|
'/** \n @Name:<%= title %> \n @License: <%= license %> \n */ \n\n'
|
|
|
|
|
,{title: 'layDate 日期与时间组件', license: 'MIT'}
|
|
|
|
|
];
|
2017-09-13 16:06:55 +08:00
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//合并所依赖的 css 文件
|
2017-09-13 16:06:55 +08:00
|
|
|
|
gulp.src('./src/css/modules/laydate/default/{font,laydate}.css')
|
|
|
|
|
.pipe(concat('laydate.css', {newLine: '\n\n'}))
|
|
|
|
|
.pipe(gulp.dest(dir + '/src/theme/default'));
|
2017-08-24 20:26:48 +08:00
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//合并所依赖的 js 文件
|
|
|
|
|
return gulp.src(['./src/modules/{lay,laydate}.js'])
|
|
|
|
|
.pipe(concat('laydate.js', {newLine: ''}))
|
|
|
|
|
.pipe(header.apply(null, notes))
|
|
|
|
|
.pipe(gulp.dest(dir + '/src'));
|
2017-08-24 20:26:48 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-09-13 16:06:55 +08:00
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|