-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
80 lines (74 loc) · 1.82 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
const
{ src, dest, parallel } = require('gulp'),
header = require('gulp-header'),
rename = require("gulp-rename"),
terser = require('gulp-terser'),
babel = require('gulp-babel'),
gutil = require('gulp-util'),
pkg = require('./package.json'),
now = new Date();
const banner = {
long: `/**
* -------------------------------------------------------------------
* <%= pkg.name %>
* <%= pkg.description %>
*
* @author <%= pkg.author %>
* @version v<%= pkg.version %>
* @link <%= pkg.homepage %>
* @license <%= pkg.license %>
* -------------------------------------------------------------------
*/
`+'\n',
short: `/*! <%= pkg.name %> v<%= pkg.version %> | (c) ${now.getFullYear()} <%= pkg.author %> | <%= pkg.license %> license | <%= pkg.homepage %> */`+'\n',
};
const getBanner = (type = 'long') => ({
value: banner[type], options: { pkg }
});
const getName = (isMin = false, type = '') => {
return [
'onscroll-effect',
type,
isMin ? 'min' : '',
'js'
]
.filter(Boolean)
.join('.');
};
const runIf = (condition, task, ...opt) => (condition ? task : gutil.noop)(...opt);
const mapTasks = [
{
name: 'es6',
head: getBanner(),
file: getName(false, 'es6')
},
{
name: 'es6:min',
head: getBanner('short'),
file: getName(true, 'es6')
},
{
name: 'es5',
head: getBanner(),
file: getName()
},
{
name: 'es5:min',
head: getBanner('short'),
file: getName(true)
}
].reduce((acc, { name, head, file }) => {
return {
...acc,
[name]() {
return src('src/index.js')
.pipe( rename(file) )
.pipe( runIf(name.includes('es5'), babel, { presets: ['@babel/env'] }) )
.pipe( runIf(name.includes('min'), terser) )
.pipe( header(head.value, head.options) )
.pipe( dest('dist') );
}
}
}, {});
const tasks = Object.keys(mapTasks).map((key) => mapTasks[key]);
exports.default = parallel(...tasks);