-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
137 lines (122 loc) · 3.24 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
126
127
128
129
130
131
132
133
134
135
136
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const imageminPngQuant = require('imagemin-pngquant');
const imageminJpegRecompress = require('imagemin-jpeg-recompress');
// lossy images plugins
const imageminMozjpeg = require('imagemin-mozjpeg');
var del = require('del');
const server = require('browser-sync').create();
var paths = {
images: {
src: './resources/img/**/*.{png,jpg,jpeg,svg,gif,pdf}',
dest: './dist/resources/img'
},
styles: {
src: './resources/css/**/*.css',
dest: './dist/resources/css'
},
scripts: {
src: './resources/js/**/*.*',
dest: './dist/resources/js'
},
data: {
src: './resources/data/**/*.*',
dest: './dist/resources/data'
},
vendors: {
src: './vendors/**/*.*',
dest: './dist/vendors'
},
rootfiles: {
src: './*.{txt,html,ico,xml,webmanifest}',
dest: './dist'
}
};
// BrowserSync
function serve(done) {
server.init({
server: {
baseDir: "./"
},
port: 3000,
notify: false
});
done();
}
// BrowserSync Reload
function serverReload(done) {
server.reload();
done();
}
function previewDist(done) {
server.init({
server: {
baseDir: './dist'
},
notify: false
});
done();
}
function clean() {
return del(['./dist']);
}
function rootfiles() {
return gulp.src(paths.rootfiles.src)
.pipe(gulp.dest(paths.rootfiles.dest));
}
function styles() {
return gulp.src(paths.styles.src)
.pipe(gulp.dest(paths.styles.dest));
}
function scripts() {
return gulp.src(paths.scripts.src)
.pipe(gulp.dest(paths.scripts.dest));
}
function data() {
return gulp.src(paths.data.src)
.pipe(gulp.dest(paths.data.dest));
}
function vendors() {
return gulp.src(paths.vendors.src)
.pipe(gulp.dest(paths.vendors.dest));
}
function images() {
return gulp.src([paths.images.src])
.pipe(imagemin(
[
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imageminMozjpeg({quality: 80}),
imagemin.optipng(),
imagemin.svgo(),
imageminPngQuant(),
imageminJpegRecompress()
],
{
progressive: true,
interlaced: true,
multipass: true,
verbose: true
}
))
.pipe(gulp.dest(paths.images.dest));
}
// Watch files
function watchFiles() {
gulp.watch("./resources/css/*.css", gulp.series(serverReload));
gulp.watch("./resources/js/*.js", gulp.series(serverReload));
gulp.watch("./resources/data/*.json", gulp.series(serverReload));
gulp.watch("./index.html", serverReload);
}
var watch = gulp.series(serve, watchFiles);
var preview = gulp.series(previewDist);
var build = gulp.series(clean, gulp.series(styles, scripts, data, vendors, rootfiles), gulp.parallel(images));
exports.watch = watch;
exports.clean = clean;
exports.images = images;
exports.styles = styles;
exports.scripts = scripts;
exports.data = data;
exports.preview = preview;
exports.build = build;
exports.default = build;