-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
125 lines (101 loc) · 3.01 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict'
const gulp = require('gulp');
const css = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const connect = require('gulp-connect');
const htmlmin = require('gulp-htmlmin');
const uglify = require('gulp-uglify-es').default;
const purgecss = require('gulp-purgecss')
const paths = {
html: '*.html',
css: 'css/**/*.css',
script: 'js/**/*.js',
sw: 'service-worker.js',
images: 'images/**',
vendor: 'libs/**/*.js',
vendor_css: 'libs/css/*.css',
manifest: 'site.webmanifest'
};
const imagemin = require('gulp-imagemin');
const imagesGulp = function() {
return gulp.src(paths.images)
.pipe(imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.mozjpeg({ quality: 75, progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo({
plugins: [
{ removeViewBox: true },
{ cleanupIDs: false }
]
})
]))
.pipe(gulp.dest('public/images'));
};
const gulpCss = function() {
return gulp.src(paths.css)
.pipe(sourcemaps.init())
.pipe(css())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/css'));
};
const jsGulp = function() {
return gulp.src(paths.script, {
ignore: [paths.sw, paths.vendor]
})
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/js'));
};
const purgeLibs = function() {
return gulp.src('libs/**/*.css')
.pipe(purgecss({
content: [paths.html]
}))
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/libs/'))
};
const copyManifest = function() {
return gulp.src(paths.manifest)
.pipe(gulp.dest('./public/'))
};
const swGulp = function() {
return gulp.src(paths.sw)
.pipe(uglify())
.pipe(gulp.dest('./public'));
};
const vendorGulp = function() {
return gulp.src(paths.vendor)
.pipe(uglify())
.pipe(gulp.dest('./public/libs'))
};
const htmlGulp = function() {
return gulp.src(paths.html)
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest('./public/'));
};
const watchJS = function() {
return gulp.watch(paths.script, gulp.series(jsGulp, reload));
};
const watchCSS = function() {
return gulp.watch(paths.css, gulp.series(gulpCss, reload));
};
const watchHTML = function() {
return gulp.watch(paths.html, gulp.series(htmlGulp, reload));
};
const server = function() {
return connect.server({ livereload: true });
};
const reload = function() {
return gulp.src(paths.html).pipe(connect.reload());
};
const watch = gulp.parallel(
watchCSS, watchJS, watchHTML
);
exports.build = gulp.parallel(jsGulp, gulpCss, imagesGulp, htmlGulp, swGulp, vendorGulp, copyManifest, purgeLibs);
exports.watch = gulp.parallel(server, watch);