-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
179 lines (156 loc) · 4.06 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const {
src,
dest,
parallel,
series,
watch
} = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const rename = require('gulp-rename');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const fileinclude = require('gulp-file-include');
const browserSync = require('browser-sync').create();
const svgSprite = require('gulp-svg-sprite');
const del = require('del');
const htmlmin = require('gulp-htmlmin');
const webp = require('gulp-webp');
const pug = require('gulp-pug');
// создаем стили
const styles = () => {
return src('./src/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyles: 'expand'
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(autoprefixer({
grid: true,
cascade: false,
}))
.pipe(cleanCSS({
level: 2
}))
.pipe(sourcemaps.write('.'))
.pipe(dest('./theme/css'))
.pipe(browserSync.stream())
}
// конвертируем картинки в webp
const webpImages = () => {
return src(['./src/**/**.{jpg,jpeg,png}'])
.pipe(webp())
.pipe(dest('./theme'))
};
const compile = () => {
return src('./src/**/*.pug')
.pipe(pug())
.pipe(dest('./theme'));
};
// добавляем шаблоны файлов
const htmlInclude = () => {
return src(['./src/*.html'])
.pipe(fileinclude({
prefix: '@',
basepath: '@file'
}))
.pipe(dest('./theme'))
.pipe(browserSync.stream())
}
// переносим картинки в themes
const imgToTheme = () => {
return src(['./src/img/**.jpg', './src/img/**.png', './src/img/**.jpeg', './src/img/**.svg'])
.pipe(dest('./theme/img'))
}
// переносим и папки если есть
const folders = () => {
return src(['./src/img/**'])
.pipe(dest('./theme/img/'))
}
// создаем спрайты
const svgSprites = () => {
return src('./src/img/**.svg')
.pipe(svgSprite ({
mode: {
stack: {
sprite: "../sprite.svg"
}
}
}))
.pipe(dest('./theme/img'))
}
// передаем всякую фигню, например, видео, в themes
const source = () => {
return src('./src/source/**')
.pipe(dest('./theme'))
}
// передаем шрифты
const fonts = () => {
return src(['./src/fonts/**.woff', './src/fonts/**.woff2'])
.pipe(dest('./theme/fonts'))
}
//передаем скрипты
const js = () => {
return src('./src/js/**/*.js')
.pipe(dest('./theme/js/'))
}
// очищаем рабочую папку
const clean = () => {
return del(['theme/*'])
}
const watchFiles = () => {
browserSync.init({
server: {
baseDir: "./theme",
index: "home.html"
}
});
watch('./src/scss/**/*.scss', styles);
watch('./src/js/**/*.js', js);
watch('./src/template-parts/*.html', htmlInclude);
watch('./src/*.html', htmlInclude);
watch('./src/*.pug', compile);
watch('./src/template-parts/*.pug', compile);
watch('./src/img/**.jpg', imgToTheme);
watch('./src/img/**.png', imgToTheme);
watch('./src/img/**.jpeg', imgToTheme);
watch('./src/img/**/**.jpg', webpImages);
watch('./src/img/**/**.png', webpImages);
watch('./src/img/**', folders);
watch('./src/img/**.svg', svgSprites);
watch('./src/source/**', source);
watch('./src/fonts/**.woff', fonts);
watch('./src/fonts/**.woff2', fonts);
}
exports.styles = styles;
exports.compile = compile;
exports.styles = styles;
exports.watchFiles = watchFiles;
exports.default = series(clean, parallel(htmlInclude, compile, fonts, imgToTheme, webpImages, source, folders, svgSprites), js, styles, watchFiles);
const stylesBuild = () => {
return src('./src/scss/**/*.scss')
.pipe(sass({
outputStyles: 'expand'
}
))
.pipe(rename({
suffix: '.min'
}))
.pipe(autoprefixer({
cascade: false,
}))
.pipe(cleanCSS({
level: 2
}))
.pipe(dest('./theme/css/'))
}
const htmlMinify = () => {
return src('./theme/**/*.html')
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(dest('./theme'));
}
exports.build = series(clean, parallel(htmlInclude, compile, fonts, imgToTheme, webpImages, source, svgSprites), stylesBuild, htmlMinify, watchFiles);