-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
82 lines (73 loc) · 2.04 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const pkg = require('./package.json');
const gulp = require('gulp');
const del = require('del');
const less = require('gulp-less');
const cssnano = require('gulp-cssnano');
const rename = require('gulp-rename');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const jshint = require('gulp-jshint');
const banner = require('gulp-banner');
const stripComments = require('gulp-strip-comments');
const removeEmptyLines = require('gulp-remove-empty-lines');
///////////////////////////////////////////////////
// 构建任务
const TASK_BUILD = ['clean', 'less', 'js'];
// banner
const PLUGIN_BANNER = '/**\n' +
' * <%= pkg.name %> <%= pkg.version %>\n' +
' * <%= pkg.description %>\n' +
' * <%= pkg.homepage %>\n' +
` * Copyright 2011 - ${new Date().getFullYear()}\n` +
' * Released under the <%= pkg.license %> license.\n' +
' */\n';
///////////////////////////////////////////////////
// 清空当前模块的构建
gulp.task('clean', async (cb) => {
await del('dist', cb);
});
// LESS
gulp.task('less', () => {
return gulp.src(['src/jquery.pager.less'])
.pipe(less())
.pipe(autoprefixer({
cascade: false
})) // 添加浏览器前缀
.pipe(banner(PLUGIN_BANNER, {
pkg: pkg
}))
.pipe(gulp.dest('dist/'))
.pipe(cssnano({
safe: true,
})) // 压缩 CSS
.pipe(rename({
suffix: '.min',
})) // 添加后缀名
.pipe(banner(PLUGIN_BANNER, {
pkg: pkg
}))
.pipe(gulp.dest('dist/'));
});
// JS
gulp.task('js', () => {
return gulp.src('src/jquery.pager.js')
.pipe(jshint())
.pipe(stripComments()) // 去除注释
.pipe(removeEmptyLines({
removeComments: true
})) // 移除空白行
.pipe(banner(PLUGIN_BANNER, {
pkg: pkg
}))
.pipe(gulp.dest('dist/'))
.pipe(uglify())
.pipe(rename({
suffix: '.min',
}))
.pipe(banner(PLUGIN_BANNER, {
pkg: pkg
}))
.pipe(gulp.dest('dist/'));
});
///////////////////////////////////////////////////
gulp.task('build', gulp.series(...TASK_BUILD));