You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
layui/gulpfile.js

241 lines
5.4 KiB

7 years ago
/**
layui构建
*/
var pkg = require('./package.json');
7 years ago
var inds = pkg.independent;
7 years ago
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');
7 years ago
var zip = require('gulp-zip');
7 years ago
//获取参数
var argv = require('minimist')(process.argv.slice(2), {
default: {
ver: 'all'
}
})
//注释
,note = [
'/** <%= pkg.name %>-v<%= pkg.version %> <%= pkg.license %> License By <%= pkg.homepage %> */\n <%= js %>'
,{pkg: pkg, js: ';'}
]
//模块
,mods = 'laytpl,laypage,laydate,jquery,layer,element,upload,form,tree,table,carousel,util,flow,layedit,code'
7 years ago
//发行版本目录
7 years ago
,releaseDir = './release/zip/layui-v' + pkg.version
7 years ago
,release = releaseDir + '/layui'
7 years ago
//任务
,task = {
//压缩js模块
minjs: function(ver) {
ver = ver === 'open';
//可指定模块压缩eggulp 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'
]
7 years ago
,dir = ver ? release : 'dist';
7 years ago
//过滤 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'
]
7 years ago
,dir = ver ? release : 'dist';
7 years ago
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'
]
7 years ago
,dir = ver ? release : 'dist';
7 years ago
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';
7 years ago
var src = [
'./src/css/**/*.css'
,'!./src/css/**/font.css'
]
7 years ago
,dir = ver ? release : 'dist'
7 years ago
,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';
7 years ago
var dir = ver ? release : 'dist';
7 years ago
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}']
7 years ago
,dir = ver ? release : 'dist';
7 years ago
if(ver || argv.open){
src.push('!./src/**/layim/**/*.*');
}
gulp.src(src).pipe(rename({}))
.pipe(gulp.dest('./'+ dir));
}
7 years ago
//复制发行的引导文件
,release: function(){
gulp.src('./release/doc/**/*')
.pipe(gulp.dest(releaseDir));
}
7 years ago
};
//清理
gulp.task('clear', function(cb) {
return del(['./dist/*'], cb);
});
gulp.task('clearRelease', function(cb) {
7 years ago
return del([releaseDir], cb);
7 years ago
});
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);
7 years ago
gulp.task('release', task.release);
7 years ago
7 years ago
//发行版
7 years ago
gulp.task('default', ['clearRelease'], function(){ //命令gulp
for(var key in task){
task[key]('open');
}
});
7 years ago
//完整任务
gulp.task('all', ['clear'], function(){ //命令gulp all过滤layimgulp all --open
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'));
7 years ago
});
7 years ago
//打包LayIM版本
7 years ago
gulp.task('layim', function(){
7 years ago
var dir = './release/zip/layui.layim-v'+ inds.layim;
7 years ago
gulp.src('./release/doc-layim/**/*')
.pipe(gulp.dest(dir))
gulp.src('./src/**/*')
.pipe(gulp.dest(dir + '/src'))
return gulp.src('./dist/**/*')
7 years ago
.pipe(gulp.dest(dir + '/dist'));
7 years ago
});
7 years ago
7 years ago