-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
115 lines (104 loc) · 2.65 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
"use strict";
const devFolder = "./src",
distFolder = "./dist";
const path = {
src: {
scss: devFolder + "/scss/style.scss",
js: devFolder + "/js/script.js",
img: devFolder + "/img/**/*.{jpg,png,gif,svg,ico,webp}",
},
dist: {
css: distFolder + "/css/",
js: distFolder + "/js/",
img: distFolder + "/img/",
},
watch: {
html: "./*.html",
scss: devFolder + "/scss/**/*.scss",
js: devFolder + "/js/**/*.js",
img: devFolder + "/img/**/*.*",
},
};
const { src, dest, series, parallel, watch } = require("gulp");
const gulp = require("gulp"),
browserSync = require("browser-sync").create(),
del = require("del"),
autoprefixer = require("gulp-autoprefixer"),
cleanCSS = require("gulp-clean-css"),
imagemin = require("gulp-imagemin"),
rename = require("gulp-rename"),
uglify = require("gulp-uglify-es").default,
concat = require("gulp-concat"),
gcmq = require("gulp-group-css-media-queries"),
sass = require("gulp-sass");
//clear dist folder
const clear = () => del(distFolder);
//styles
const styles = () =>
src(path.src.scss)
.pipe(sass().on("error", sass.logError))
.pipe(gcmq())
.pipe(
autoprefixer({
overrideBrowserslist: ["last 3 versions"],
})
)
.pipe(
cleanCSS({
compatibility: "ie8",
})
)
.pipe(
rename({
suffix: ".min",
})
)
.pipe(dest(path.dist.css))
.pipe(browserSync.stream());
//scripts
const scripts = () =>
// src(["./src/js/jquery-3.5.1.min.js", "./src/js/script.js"]) * шаблон подключения js
src(path.src.js)
.pipe(concat("script.js"))
.pipe(uglify())
.pipe(
rename({
suffix: ".min",
})
)
.pipe(dest(path.dist.js))
.pipe(browserSync.stream());
// picture
const picture = () =>
src(path.src.img)
.pipe(
imagemin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
interlaced: true,
optimizationLevel: 3,
})
)
.pipe(dest(path.dist.img))
.pipe(browserSync.stream());
//watcher
const watcher = () => {
browserSync.init({
server: {
baseDir: "./",
},
port: 3000,
notify: false,
});
watch(path.watch.html).on("change", browserSync.reload);
watch(path.watch.js, scripts).on("change", browserSync.reload);
watch(path.watch.scss, styles).on("change", browserSync.reload);
watch(path.watch.img, picture).on("change", browserSync.reload);
};
exports.watcher = watcher;
exports.scripts = scripts;
exports.picture = picture;
exports.clear = clear;
exports.styles = styles;
exports.build = series(clear, parallel(styles, scripts, picture));
exports.dev = watcher;