-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (81 loc) · 1.91 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
/* eslint-disable no-console */
const gulp = require("gulp");
const plugins = require("gulp-load-plugins")();
const del = require("del");
const files = {
html: "src/**/*.html",
js: ["src/**/*.js", "!src/**/lib/**"],
css: "src/**/*.css",
static: ["src/**/lib/**", "src/**/*.png"],
build: "dist",
};
const clean = () => del([`${files.build}/*`]);
const buildHTML = () =>
gulp
.src(files.html)
.pipe(
plugins.htmlmin({
collapseBooleanAttributes: true,
collapseWhitespace: true,
includeAutoGeneratedTags: false,
minifyCSS: true,
minifyJS: true,
processConditionalComments: true,
removeComments: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
})
)
.pipe(gulp.dest(files.build))
.on("error", console.error);
const buildJS = () =>
gulp
.src(files.js)
.pipe(
plugins.babel({
presets: ["@babel/env"],
})
)
.pipe(
plugins.uglify({
output: {
ascii_only: true,
},
})
)
.pipe(gulp.dest(files.build))
.on("error", console.error);
const buildCSS = () =>
gulp
.src(files.css)
.pipe(plugins.plumber())
.pipe(
plugins.cleanCss({
level: {
2: {
all: true,
},
},
})
)
.pipe(gulp.dest(files.build))
.on("error", console.error);
const buildStatic = () =>
gulp
.src(files.static)
.pipe(gulp.dest(files.build))
.on("error", console.error);
const build = gulp.series(
clean,
gulp.parallel(buildHTML, buildJS, buildCSS, buildStatic)
);
const watch = () => {
gulp.watch(files.html, buildHTML);
gulp.watch(files.js, buildJS);
gulp.watch(files.css, buildCSS);
gulp.watch(files.static, buildStatic);
};
exports.build = build;
exports.watch = watch;
exports.default = gulp.series(build, watch);