一套开源的 Web UI 组件库。采用自身极简的模块化规范,并遵循原生 HTML/CSS/JS 的开发模式,极易上手,开箱即用。非常适合网页界面的快速构建。
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.

173 lines
4.6 KiB

2 years ago
'use strict';
7 years ago
2 years ago
const pkg = require('./package.json');
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const cleanCSS = require('gulp-clean-css');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const header = require('gulp-header');
const footer = require('gulp-footer');
const del = require('del');
const minimist = require('minimist');
const yargs = require('yargs');
3 years ago
3 years ago
// 基础配置
2 years ago
const config = {
// 注释
3 years ago
comment: [
'/** v<%= pkg.version %> | <%= pkg.license %> Licensed */<%= js %>',
{pkg: pkg, js: ';'}
],
// 模块
modules: 'lay,laytpl,laypage,laydate,jquery,layer,util,dropdown,slider,colorpicker,element,upload,form,table,treeTable,tree,transfer,carousel,rate,flow,code'
3 years ago
};
7 years ago
3 years ago
// 获取参数
2 years ago
const argv = require('minimist')(process.argv.slice(2), {
7 years ago
default: {
3 years ago
version: pkg.version
7 years ago
}
3 years ago
});
3 years ago
// 前置目录
2 years ago
const dir = {
3 years ago
rls: './release/zip/layui-v' + pkg.version
7 years ago
};
3 years ago
// 输出目录
2 years ago
const dest = ({
dist: './dist',
rls: dir.rls + '/layui'
3 years ago
}[argv.dest || 'dist'] || argv.dest) + (argv.vs ? '/'+ pkg.version : '');
7 years ago
3 years ago
// js
2 years ago
const js = () => {
let src = [
3 years ago
'./src/**/{layui,layui.all,'+ config.modules +'}.js'
];
return gulp.src(src).pipe(uglify({
output: {
ascii_only: true // escape Unicode characters in strings and regexps
2 years ago
},
ie: true
3 years ago
})).pipe(concat('layui.js', {newLine: ''}))
.pipe(header.apply(null, config.comment))
.pipe(gulp.dest(dest));
};
3 years ago
// css
2 years ago
const css = () => {
let src = [
'./src/css/layui.css',
'./src/css/modules/**/*.css',
'!./src/css/**/font.css'
2 years ago
];
3 years ago
return gulp.src(src).pipe(cleanCSS({
compatibility: 'ie8'
}))
.pipe(concat('layui.css', {newLine: ''}))
3 years ago
.pipe(gulp.dest(dest +'/css'));
};
3 years ago
// files
2 years ago
const files = () => {
let src = ['./src/**/*.{eot,svg,ttf,woff,woff2,html,json,png,jpg,gif}'];
3 years ago
return gulp.src(src)
.pipe(gulp.dest(dest));
};
7 years ago
3 years ago
// cp
2 years ago
const cp = () => {
3 years ago
return gulp.src('./dist/**/*')
.pipe(gulp.dest(dest));
};
3 years ago
// release
2 years ago
const rls = () => {
3 years ago
return gulp.src('./release/doc/**/*')
.pipe(replace(/[^'"]+(\/layui\.css)/, 'layui/css$1')) // 替换 css 引入路径中的本地 path
.pipe(replace(/[^'"]+(\/layui\.js)/, 'layui$1')) // 替换 js 引入路径中的本地 path
3 years ago
.pipe(gulp.dest(dir.rls));
};
7 years ago
3 years ago
// clean
2 years ago
const clean = cb => {
3 years ago
return del([dest], {
force: true
});
};
2 years ago
const cleanRLS = cb => {
3 years ago
return del([dir.rls]);
};
7 years ago
3 years ago
// Define all task
3 years ago
exports.js = js;
exports.css = css;
exports.files = files;
exports.default = gulp.series(clean, gulp.parallel(js, css, files)); // default task
3 years ago
exports.cp = gulp.series(clean, cp);
exports.rls = gulp.series(cleanRLS, rls); // release task
3 years ago
3 years ago
// layer task
2 years ago
exports.layer = () => { // gulp layer
let dest = './release/layer';
7 years ago
gulp.src('./src/css/modules/layer.css')
.pipe(gulp.dest(dest + '/src'));
7 years ago
4 years ago
return gulp.src('./src/modules/layer.js')
3 years ago
.pipe(gulp.dest(dest + '/src'));
};
7 years ago
3 years ago
// laydate task
2 years ago
exports.laydate = () => { // gulp laydate
let dest = './release/laydate/'; // 发行目录
2 years ago
let comment = [ // 注释
'\n/** \n * <%= title %> \n * <%= license %> Licensed \n */ \n\n'
,{title: 'laydate 日期与时间组件(单独版)', license: 'MIT'}
4 years ago
];
7 years ago
3 years ago
// css
3 years ago
gulp.src('./src/css/modules/laydate.css')
.pipe(gulp.dest(dest + 'src'));
7 years ago
3 years ago
// js
4 years ago
return gulp.src(['./src/layui.js', './src/modules/{lay,laydate}.js'])
3 years ago
.pipe(replace('win.layui =', 'var layui =')) // 将 layui 替换为局部变量
.pipe(replace('}(window); // gulp build: layui-footer', '')) // 替换 layui.js 的落脚
.pipe(replace(';!function(window){ // gulp build: lay-header', '')) // 替换 lay.js 的头部
.pipe(replace('}(window, window.document); // gulp build: lay-footer', '')) // 替换 lay.js 的落脚
3 years ago
.pipe(concat('laydate.js', {newLine: ''}))
.pipe(replace(';!function(window, document){ // gulp build: laydate-header', '')) // 替换 laydate.js 的头部
.pipe(header.apply(null, comment)) // 追加头部
3 years ago
.pipe(gulp.dest(dest + 'src'));
};
7 years ago
3 years ago
// helper
2 years ago
exports.help = () => {
let usage = '\nUsage: gulp [options] tasks';
let parser = yargs.usage(usage, {
3 years ago
dest: {
type: 'string',
desc: '定义输出目录,可选项:dist(默认)、rls、任意路径'
},
vs: {
type: 'boolean',
desc: '生成一个带版本号的文件夹'
3 years ago
}
});
parser.showHelp(console.log);
console.log([
'Tasks:',
' default 默认任务',
' rls 发行任务',
' cp 将 dist 目录复制一份到参数 --dest 指向的目录'
3 years ago
].join('\n'), '\n\nExamples:\n gulp cp --dest ./v --vs', '\n');
3 years ago
return gulp.src('./');
};
7 years ago