-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
157 lines (127 loc) · 5.21 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
import gulp from "gulp"; // GULP
import { paths } from "./gulp/path.js"; // Пути
import del from "del"; // Удаление файлов
import fileinclude from "gulp-file-include"; // Шаблонизатор html
import replace from "gulp-replace"; // Подмена путей
import gulpPlumber from "gulp-plumber"; // Вывод
import notify from "gulp-notify"; // ошибок
import browserSync from "browser-sync"; // Автоперезагрузка
import dartSass from "sass"; // Препроцессор
import gulpSass from "gulp-sass"; // SCSS
import rename from "gulp-rename"; // Переименование
import autoPrefixer from "gulp-autoprefixer"; // Автопрефиксы
import cleanCss from "gulp-cleancss" // Минификация css файла
import imagemin from "gulp-imagemin"; // Опитимизация фото
import newer from "gulp-newer";
import sourcemaps from "gulp-sourcemaps"
import babel from "gulp-babel";
import GulpUglify from "gulp-uglify";
import webpack from "webpack-stream";
// ======================================================================== ^ Импорты
const copy = () => { // Копирование файлов из
return gulp.src(paths.src.files) // .src/files/
.pipe(gulp.dest(paths.dist.files)) // в ->
} // .dist/files/
const reset = () => { // Удаление
return del(paths.clean) // файлов
} // перед копированием
const html = () => { // Обработка html
return gulp.src(paths.src.html) //
.pipe(gulpPlumber(
notify.onError({ // Вывод ошибок html
title: "HTML",
message: "Error: <%= error.message %>"
})
))
.pipe(fileinclude()) // Шаблонизатор
.pipe(replace(/@img\//g, 'img/')) // Подмена путей img
.pipe(gulp.dest(paths.dist.html)) //
.pipe(browserSync.stream()) // Автоперезагрузка html
} //
const sass = gulpSass(dartSass);
const scss = () => {
return gulp.src(paths.src.scss)
.pipe(sourcemaps.init())
.pipe(gulpPlumber(
notify.onError({ // Вывод ошибок scss
title: "SCSS",
message: "Error: <%= error.message %>"
})
))
.pipe(replace(/@img\//g, 'img/')) // Подмена путей img
.pipe(sass({
outputStyle: "expanded"
}))
.pipe(autoPrefixer({
grid:true,
cascade: true,
overrideBrowserslist: ["last 3 versions"]
}))
.pipe(cleanCss())
.pipe(rename({
extname: ".min.css"
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.dist.css))
.pipe(browserSync.stream())
}
const image = () => {
return gulp.src(paths.src.img)
.pipe(gulpPlumber(
notify.onError({ // Вывод ошибок scss
title: "IMAGE",
message: "Error: <%= error.message %>"
})
))
.pipe(newer(paths.dist.img))
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
interlaced: true,
optimizationLevel: 3
}))
.pipe(gulp.dest(paths.dist.img))
.pipe(gulp.src(paths.src.svg))
.pipe(gulp.dest(paths.dist.img))
.pipe(browserSync.stream())
}
const js = () => {
return gulp.src(paths.src.js)
.pipe(gulpPlumber(
notify.onError({ // Вывод ошибок scss
title: "JS",
message: "Error: <%= error.message %>"
})
))
.pipe(webpack({
mode: "development",
output: {
filename: "script.min.js"
}
}))
.pipe(babel({
presets: ["@babel/env"]
}))
.pipe(GulpUglify())
.pipe(gulp.dest(paths.dist.js))
.pipe(browserSync.stream())
}
const server = (done) => {
browserSync.init({
server: {
baseDir: `${paths.dist.html}`
},
notify: false,
port: 3000,
})
}
function watcher () { // Установка
gulp.watch( paths.watch.files, copy) // наблюдателя
gulp.watch( paths.watch.html, html)
gulp.watch( paths.watch.scss, scss)
gulp.watch( paths.watch.js, js)
gulp.watch( paths.watch.img, image)
} //
const mainTasks = gulp.parallel(copy, html, scss, js, image);
const dev = gulp.series(reset, mainTasks, gulp.parallel(watcher, server));
gulp.task("default", dev)