-
Notifications
You must be signed in to change notification settings - Fork 96
/
gulpfile.js
103 lines (96 loc) · 2.93 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// include plug-ins
var gulp = require('gulp');
var concat = require('gulp-concat');
var umd = require('gulp-umd');
var inject = require('gulp-inject-string')
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var babel = require('gulp-babel');
var HEADER_COMMENT = '// Pressure v2.2.0 | Created By Stuart Yamartino | MIT License | 2015 - 2020\n';
var DESTINATION = '.';
// JS concat, strip debugging and minify
async function build() {
gulp.src([
'./src/pressure.js',
'./src/element.js',
'./src/adapters/adapter.js',
'./src/adapters/adapter_force_touch.js',
'./src/adapters/adapter_3d_touch.js',
'./src/adapters/adapter_pointer.js',
'./src/config.js',
'./src/helpers.js',
])
.pipe(concat('dist/pressure.js'))
.pipe(babel())
.pipe(umd({
exports: function() {
return 'Pressure';
}
}))
.pipe(inject.prepend(HEADER_COMMENT))
// This will output the non-minified version
.pipe(gulp.dest(DESTINATION))
// This will minify and rename to pressure.min.js
.pipe(uglify())
.pipe(inject.prepend(HEADER_COMMENT))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(DESTINATION));
}
async function buildJquery() {
gulp.src([
'./src/jquery_pressure.js',
'./src/element.js',
'./src/adapters/adapter.js',
'./src/adapters/adapter_force_touch.js',
'./src/adapters/adapter_3d_touch.js',
'./src/adapters/adapter_pointer.js',
'./src/config.js',
'./src/helpers.js',
])
.pipe(concat('dist/jquery.pressure.js'))
.pipe(babel())
.pipe(umd({
dependencies: function() {
return [
{
name: 'jquery',
amd: 'jquery',
cjs: 'jquery',
global: 'jQuery',
param: '$'
}
]
},
/**
* The UMD wrapper expects an exports() string for an expression the factory() should return,
* and a namespace() string for a global value that should be set when no loader is present.
* However, since jquery_pressure.js mutates $ several times instead of returning a value,
* it does not need to use these features, so we set them to harmless no-ops.
*/
namespace: function() {
// sets `window.jQuery__pressure` to undefined
return 'jQuery__pressure';
},
exports: function() {
// safely returns undefined from factory
return 'void 0';
}
}))
.pipe(inject.prepend(HEADER_COMMENT))
// This will output the non-minified version
.pipe(gulp.dest(DESTINATION))
// This will minify and rename to jquery.pressure.min.js
.pipe(uglify())
.pipe(inject.prepend(HEADER_COMMENT))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(DESTINATION));
}
function watch() {
gulp.watch(['src/*', 'src/adapters/*'], build);
gulp.watch(['src/*', 'src/adapters/*'], buildJquery);
}
var dist = gulp.series(build, buildJquery)
exports.build = build;
exports.buildJquery = buildJquery;
exports.watch = watch;
exports.dist = dist;