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

178 lines
4.0 KiB

4 years ago
7 years ago
/**
4 years ago
layui Build
7 years ago
*/
var pkg = require('./package.json');
7 years ago
var inds = pkg.independents;
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');
4 years ago
var replace = require('gulp-replace');
7 years ago
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 = [
4 years ago
'/** <%= pkg.realname %> v<%= pkg.version %> | Released under the <%= pkg.license %> license */\n <%= js %>'
7 years ago
,{pkg: pkg, js: ';'}
]
//模块
4 years ago
,mods = 'lay,laytpl,laypage,laydate,jquery,layer,util,element,upload,dropdown,slider,colorpicker,form,tree,transfer,table,carousel,rate,flow,layedit,code'
7 years ago
7 years ago
//发行版本目录
7 years ago
,releaseDir = './release/zip/layui-v' + pkg.version
7 years ago
,release = releaseDir + '/layui'
7 years ago
//目标木
,destDir = function(ver){
return ver ? release : function(){
return argv.rc ? 'rc' : 'dist'
}();
}
7 years ago
//任务
,task = {
4 years ago
//聚合 JS 文件
alljs: function(ver){
7 years ago
var src = [
'./src/**/{layui,all,'+ mods +'}.js'
]
7 years ago
,dir = destDir(ver);
7 years ago
return gulp.src(src).pipe(uglify())
4 years ago
.pipe(concat('layui.js', {newLine: ''}))
7 years ago
.pipe(header.apply(null, note))
.pipe(gulp.dest('./'+ dir));
}
4 years ago
//压缩 css 文件
7 years ago
,mincss: function(ver){
7 years ago
var src = [
'./src/css/**/*.css'
,'!./src/css/**/font.css'
]
7 years ago
,dir = destDir(ver)
7 years ago
,noteNew = JSON.parse(JSON.stringify(note));
noteNew[1].js = '';
return gulp.src(src).pipe(minify({
compatibility: 'ie7'
4 years ago
})) //.pipe(header.apply(null, noteNew))
7 years ago
.pipe(gulp.dest('./'+ dir +'/css'));
}
//复制iconfont文件
,font: function(ver){
7 years ago
var dir = destDir(ver);
7 years ago
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}']
7 years ago
,dir = destDir(ver);
7 years ago
gulp.src(src).pipe(rename({}))
.pipe(gulp.dest('./'+ dir));
}
7 years ago
//复制发行的引导文件
,release: function(){
gulp.src('./release/doc/**/*')
4 years ago
.pipe(replace('http://local.res.layui.com/layui/dist/', 'layui/'))
7 years ago
.pipe(gulp.dest(releaseDir));
}
7 years ago
};
//清理
gulp.task('clear', function(cb) {
7 years ago
return del(['./'+ (argv.rc ? 'rc' : 'dist') +'/*'], cb);
7 years ago
});
gulp.task('clearRelease', function(cb) {
7 years ago
return del([releaseDir], cb);
7 years ago
});
gulp.task('alljs', task.alljs);
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
4 years ago
//完整任务 gulp
gulp.task('default', ['clear'], function(){ //rc 版gulp --rc
7 years ago
for(var key in task){
4 years ago
task[key]();
7 years ago
}
});
4 years ago
//发行版 gulp rls
gulp.task('rls', ['clearRelease'], function(){ // gulp rls
7 years ago
for(var key in task){
4 years ago
task[key]('release');
7 years ago
}
});
7 years ago
//打包 layer 独立版
7 years ago
gulp.task('layer', function(){
var dir = './release/layer';
gulp.src('./src/css/modules/layer/default/*')
.pipe(gulp.dest(dir + '/src/theme/default'));
4 years ago
return gulp.src('./src/modules/layer.js')
7 years ago
.pipe(gulp.dest(dir + '/src'));
});
4 years ago
7 years ago
//打包 layDate 独立版
7 years ago
gulp.task('laydate', function(){
4 years ago
//发行目录
var dir = './release/laydate'
//注释
,notes = [
'/** \n @Name<%= title %> \n @License: <%= license %> \n */ \n\n'
,{title: 'layDate 日期与时间组件', license: 'MIT'}
];
7 years ago
4 years ago
//合并所依赖的 css 文件
7 years ago
gulp.src('./src/css/modules/laydate/default/{font,laydate}.css')
.pipe(concat('laydate.css', {newLine: '\n\n'}))
.pipe(gulp.dest(dir + '/src/theme/default'));
7 years ago
4 years ago
//合并所依赖的 js 文件
return gulp.src(['./src/modules/{lay,laydate}.js'])
.pipe(concat('laydate.js', {newLine: ''}))
.pipe(header.apply(null, notes))
.pipe(gulp.dest(dir + '/src'));
7 years ago
});
7 years ago
7 years ago