-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
161 lines (145 loc) · 4.18 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const { src, dest, watch, parallel, series } = require("gulp");
const browserSync = require("browser-sync").create();
const scss = require("gulp-sass")(require("sass"));
const autoprefixer = require("gulp-autoprefixer");
const concat = require("gulp-concat");
const newer = require("gulp-newer");
const webp = require("gulp-webp");
const imagemin = require("gulp-imagemin");
const fonter = require("gulp-fonter");
const tt2woff2 = require("gulp-ttf2woff2");
const del = require("del");
const plumber = require("gulp-plumber");
const notifier = require("gulp-notifier");
const ghPages = require("gulp-gh-pages");
const buildPath = "./build";
const srcPath = "./src";
const path = {
src: {
html: `${srcPath}/*.html`,
css: `${srcPath}/css/*.css`,
scss: `${srcPath}/scss/style.scss`,
js: `${srcPath}/js/**/*.js`,
img: `${srcPath}/assets/img/**/*.{jpg,jpeg,png,svg,gif}`,
fonts: `${srcPath}/assets/fonts/**/*.{eot,ttf,woff,woff2,svg}`,
favicon: `${srcPath}/favicon.{ico,png,svg}`,
},
build: {
html: `${buildPath}/`,
css: `${buildPath}/css/`,
js: `${buildPath}/js/`,
img: `${buildPath}/assets/images/`,
fonts: `${buildPath}/fonts/`,
favicon: `${buildPath}/`,
},
watch: {
html: `${srcPath}/*.html`,
css: `${srcPath}/css/*.css`,
scss: `${srcPath}/scss/**/*.scss`,
js: `${srcPath}/js/**/*.js`,
img: `${srcPath}/assets/img/**/*.{jpg,jpeg,png,svg,gif}`,
fonts: `${srcPath}/assets/fonts/**/*.{eot,ttf,woff,woff2,svg}`,
favicon: `${srcPath}/favicon.{ico,png,svg}`,
},
clean: `${buildPath}/*`,
ignore: {
img: `!${buildPath}/assets`,
fonts: `!${buildPath}/fonts`,
},
deploy: `${buildPath}/**/*`,
};
function sync() {
browserSync.init({
server: {
baseDir: buildPath,
},
notify: false,
port: 3000,
});
}
function htmlTask() {
return src(path.src.html)
.pipe(dest(path.build.html))
.pipe(browserSync.reload({ stream: true }));
}
function cssTask() {
return src(path.src.css)
.pipe(dest(path.build.css))
.pipe(browserSync.reload({ stream: true }));
}
function scssTask() {
return src(path.src.scss)
.pipe(plumber({ errorHandler: notifier.error }))
.pipe(scss())
.pipe(autoprefixer({ overrideBrowserslist: ["last 5 version"] }))
.pipe(dest(path.build.css))
.pipe(concat("style.min.css"))
.pipe(scss({ outputStyle: "compressed" }))
.pipe(dest(path.build.css))
.pipe(browserSync.reload({ stream: true }));
}
function jsTask() {
return src(path.src.js)
.pipe(plumber({ errorHandler: notifier.error }))
.pipe(dest(path.build.js))
.pipe(browserSync.reload({ stream: true }));
}
function imgTask() {
return src(path.src.img)
.pipe(plumber({ errorHandler: notifier.error }))
.pipe(newer(path.build.img))
.pipe(webp())
.pipe(dest(path.build.img))
.pipe(src(path.src.img))
.pipe(newer(path.build.img))
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.mozjpeg({ quality: 80, progressive: true }),
imagemin.optipng({ optimizationLevel: 4 }),
imagemin.svgo({
plugins: [{ removeViewBox: false }],
}),
])
)
.pipe(dest(path.build.img));
}
function fontsTask() {
return src(path.src.fonts)
.pipe(plumber({ errorHandler: notifier.error }))
.pipe(newer(path.build.fonts))
.pipe(fonter({ formats: ["eot", "ttf", "woff"] }))
.pipe(dest(path.build.fonts))
.pipe(tt2woff2())
.pipe(dest(path.build.fonts));
}
function faviconTask() {
return src(path.src.favicon).pipe(dest(path.build.favicon));
}
function cleanDest() {
return del([path.clean, path.ignore.img, path.ignore.fonts]);
}
function deploy() {
return src(path.deploy).pipe(ghPages());
}
function watcher() {
watch([path.watch.html], htmlTask);
watch([path.watch.css], cssTask);
watch([path.watch.scss], scssTask);
watch([path.watch.js], jsTask);
watch([path.watch.img], imgTask);
watch([path.watch.fonts], fontsTask);
watch([path.watch.favicon], faviconTask);
}
const tasks = parallel(
htmlTask,
cssTask,
scssTask,
jsTask,
imgTask,
fontsTask,
faviconTask
);
const dev = series(cleanDest, tasks, parallel(watcher, sync));
exports.default = dev;
exports.deploy = deploy;