generated from kelvinkamau/Vibranium
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
120 lines (106 loc) · 2.49 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
'use strict'
const browserSync = require('browser-sync').create();
const del = require('del');
const gulp = require('gulp');
const cleanCss = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const htmlmin = require('gulp-htmlmin');
const uglify = require('gulp-uglify-es').default;
const imagemin = require('gulp-imagemin');
const ROOT = 'dist/';
const paths = {
html: 'src/*.html',
css: 'src/css/**/*.css',
js: 'src/js/**/*.js',
sw: 'src/service-worker.js',
images: 'src/images/**',
vendor: 'src/js/vendors/*.js',
manifest: 'src/manifest.json'
};
function browserSyncTask(done) {
browserSync.init({
server: {
baseDir: "./src/"
},
port: 8080
});
done();
}
function clean() {
return del([".dist/"]);
}
function images() {
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(ROOT + 'images'));
};
function css() {
return gulp
.src(paths.css)
.pipe(sourcemaps.init())
.pipe(cleanCss())
.pipe(sourcemaps.write())
.pipe(gulp.dest(ROOT + 'css'))
.pipe(browserSync.stream());
};
function js() {
return gulp
.src(paths.js, {ignore: [paths.sw, paths.vendor]})
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(ROOT + 'js'))
.pipe(browserSync.stream());
};
function manifest() {
return gulp
.src(paths.manifest)
.pipe(gulp.dest(ROOT))
.pipe(browserSync.stream());
};
function sw() {
return gulp
.src(paths.sw)
.pipe(uglify())
.pipe(gulp.dest(ROOT))
.pipe(browserSync.stream());
};
function vendor() {
return gulp
.src(paths.vendor)
.pipe(uglify())
.pipe(gulp.dest(ROOT + '/js/vendors'))
.pipe(browserSync.stream());
};
function html() {
return gulp.src(paths.html)
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest(ROOT))
.pipe(browserSync.stream());
};
function watchFiles() {
gulp.watch(paths.js, js);
gulp.watch(paths.css, css);
gulp.watch(paths.html, html);
gulp.watch(paths.images, images);
};
exports.build = gulp.series(
clean,
gulp.parallel(js, css, html, images, sw, vendor, manifest)
);
exports.watch = gulp.parallel(watchFiles, browserSyncTask);