-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
111 lines (97 loc) · 2.4 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
"use strict";
// Импортируем плагины
import gulp from "gulp";
import browserSync, { watch } from "browser-sync";
import dartSass from "sass";
import gulpSass from "gulp-sass";
import cssAutoprefixer from "gulp-autoprefixer";
import gcmq from "gulp-group-css-media-queries";
import { deleteAsync } from "del";
import notify from "gulp-notify";
import plumber from "gulp-plumber";
const sass = gulpSass(dartSass);
// Храним пути в массиве
const paths = {
views: {
src: "./src/index.html",
build: "./build/",
watch: "./src/index.html",
},
styles: {
src: "./src/main.scss",
build: "./build/",
watch: "./src/main.scss",
},
baseDir: "./build/",
};
// Задания для gulp
// -> Обрабатываем html
gulp.task("html", () => {
return gulp
.src(paths.views.src)
.pipe(
plumber({
errorHandler: notify.onError(function (err) {
return {
title: "HTML",
sound: false,
message: err.message,
};
}),
})
)
.pipe(gulp.dest(paths.views.build))
.pipe(browserSync.reload({ stream: true }));
});
// -> Обрабатываем scss
gulp.task("styles", () => {
return gulp
.src(paths.styles.src)
.pipe(
plumber({
errorHandler: notify.onError(function (err) {
return {
title: "STYLES",
sound: false,
message: err.message,
};
}),
})
)
.pipe(sass.sync().on("error", sass.logError))
.pipe(
cssAutoprefixer({
overrideBrowserslist: ["last 6 versions"],
})
)
.pipe(gcmq())
.pipe(gulp.dest(paths.styles.build))
.pipe(browserSync.stream());
});
// Следим за изменениями файлов
gulp.task("watcher", () => {
watch(paths.views.watch, gulp.parallel("html"));
watch(paths.styles.watch, gulp.parallel("styles"));
});
// Удаление директории build/
gulp.task("clean:build", function () {
return deleteAsync(paths.baseDir);
});
// локальный сервер
gulp.task("localServer", () => {
browserSync.init({
server: {
baseDir: paths.baseDir,
},
notify: false,
});
});
// Запуск по команде gulp
gulp.task(
"default",
gulp.series(
gulp.parallel("clean:build"),
gulp.parallel("html", "styles"),
gulp.parallel("localServer", "watcher")
)
);