-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (87 loc) · 2.11 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
const gulp = require("gulp");
const ts = require("gulp-typescript");
const terser = require("gulp-terser");
const replace = require("gulp-replace");
// Load TypeScript configuration
const tsProject = ts.createProject("tsconfig.json");
const methodNames = [
"bindMethods",
"toggleEventListeners",
"handleSlotChange",
"initProperties",
"setIndex",
"down",
"move",
"updateSliderPosition",
"up",
"keydown",
"adjustPosition",
"setScrollPosition",
"setShown",
"createResizeObserver",
"getItemOffsets",
"getContentChildren",
"isCurrentSlider",
"render",
"isDragging",
"passedThreshold",
"movementStartX",
"finalScrollPosition",
"maxWidth",
"sliderWidth",
"reachedEnd",
"currentScrollPosition",
"threshold",
"currentIndex",
"shown",
"maxWidth",
"contentElement",
"sliderElement",
].join("|");
function typescript() {
return tsProject.src().pipe(tsProject()).pipe(gulp.dest("dist"));
}
function minify() {
return gulp
.src("dist/**/*.js")
.pipe(
replace(
/(<style>[^<]+<\/style>[\s\S]*?<div class="slider">[\s\S]*?<\/div>[\s\S]*?<\/div>)/g,
match => match.replace(/\s{2,}/g, ' ').replace(/\n/g, '')
)
)
.pipe(
terser({
ecma: 2020,
module: true,
toplevel: true,
compress: {
drop_console: true,
drop_debugger: true,
},
mangle: {
properties: {
regex: new RegExp(methodNames),
},
},
format: {
comments: false,
beautify: false,
},
keep_classnames: false,
keep_fnames: false,
safari10: true,
})
)
.pipe(gulp.dest("../rememo/client/static/js"));
// .pipe(gulp.dest("dist"));
}
function watchFiles() {
gulp.watch("src/**/*.ts", typescript);
gulp.watch("dist/**/*.js", minify);
}
function watchFiles() {
gulp.watch("src/**/*.ts", gulp.series(typescript, minify));
}
exports.default = gulp.series(typescript, minify);
exports.watch = gulp.series(exports.default, watchFiles);