generated from kelvinkamau/Vibranium
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
109 lines (90 loc) · 2.51 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
'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 paths = {
html: 'src/*.html',
css: 'src/css/**/*.css',
script: 'src/js/**/*.js',
sw: 'src/service-worker.js',
images: 'src/images/**',
vendor: 'src/js/vendors/*.js',
manifest: 'src/manifest.json'
};
const imagemin = require('gulp-imagemin');
const imagesGulp = function() {
return gulp.src(paths.images)
.pipe(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
]))
.pipe(gulp.dest('dist/images'));
};
const gulpCss = function() {
return gulp.src(paths.css)
.pipe(sourcemaps.init())
.pipe(css())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/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('dist/js'));
};
const copyManifest = function() {
return gulp.src(paths.manifest)
.pipe(gulp.dest('./'))
};
const swGulp = function() {
return gulp.src(paths.sw)
.pipe(uglify())
.pipe(gulp.dest('./'));
};
const vendorGulp = function() {
return gulp.src(paths.vendor)
.pipe(uglify())
.pipe(gulp.dest('./dist/js/vendors'))
};
const htmlGulp = function() {
return gulp.src(paths.html)
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest('./'));
};
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(imagesGulp, jsGulp, gulpCss, htmlGulp, swGulp, vendorGulp, copyManifest);
exports.watch = gulp.parallel(server, watch);