-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
151 lines (133 loc) · 3.36 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
import gulp from 'gulp';
import plumber from 'gulp-plumber';
import gulpIf from 'gulp-if';
import dartSass from "sass";
import gulpSass from "gulp-sass";
import postcss from 'gulp-postcss';
import postUrl from 'postcss-url';
import autoprefixer from 'autoprefixer';
import csso from 'postcss-csso';
import terser from 'gulp-terser';
import squoosh from 'gulp-libsquoosh';
import svgo from 'gulp-svgmin';
import { stacksvg } from "gulp-stacksvg";
import { deleteAsync } from 'del';
import browser from 'browser-sync';
import bemlinter from 'gulp-html-bemlinter';
import { htmlValidator } from "gulp-w3c-html-validator";
const sass = gulpSass(dartSass);
let isDevelopment = true;
export function processMarkup () {
return gulp.src('source/*.html')
.pipe(gulp.dest('build'));
}
export function lintBem () {
return gulp.src('source/*.html')
.pipe(bemlinter());
}
export function validateMarkup () {
return gulp.src('source/*.html')
.pipe(htmlValidator.analyzer())
.pipe(htmlValidator.reporter({ throwErrors: true }));
}
export function processStyles () {
return gulp.src('source/sass/*.scss', { sourcemaps: isDevelopment })
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
postUrl({ assetsPath: '../' }),
autoprefixer(),
csso()
]))
.pipe(gulp.dest('build/css', { sourcemaps: isDevelopment }))
.pipe(browser.stream());
}
export function processScripts () {
return gulp.src('source/js/**/*.js')
.pipe(terser())
.pipe(gulp.dest('build/js'))
.pipe(browser.stream());
}
export function optimizeImages () {
return gulp.src('source/img/**/*.{png,jpg}')
.pipe(gulpIf(!isDevelopment, squoosh()))
.pipe(gulp.dest('build/img'))
}
export function createWebp () {
return gulp.src(['source/img/**/*.{png,jpg}', '!source/img/favicons/*'])
.pipe(squoosh({
webp: {}
}))
.pipe(gulp.dest('build/img'))
}
export function optimizeVector () {
return gulp.src(['source/img/**/*.svg', '!source/img/icons/**/*.svg'])
.pipe(svgo())
.pipe(gulp.dest('build/img'));
}
export function createStack () {
return gulp.src('source/img/icons/**/*.svg')
.pipe(svgo())
.pipe(stacksvg())
.pipe(gulp.dest('build/img/icons'));
}
export function copyAssets () {
return gulp.src([
'source/fonts/**/*.{woff2,woff}',
'source/*.ico',
'source/*.webmanifest',
], {
base: 'source'
})
.pipe(gulp.dest('build'));
}
export function startServer (done) {
browser.init({
server: {
baseDir: 'build'
},
cors: true,
notify: false,
ui: false,
});
done();
}
function reloadServer (done) {
browser.reload();
done();
}
function watchFiles () {
gulp.watch('source/sass/**/*.scss', gulp.series(processStyles));
gulp.watch('source/js/**/*.js', gulp.series(processScripts));
gulp.watch('source/*.html', gulp.series(processMarkup, reloadServer));
}
function compileProject (done) {
gulp.parallel(
processMarkup,
processStyles,
processScripts,
optimizeVector,
createStack,
copyAssets,
optimizeImages,
createWebp
)(done);
}
function deleteBuild () {
return deleteAsync('build');
}
export function buildProd (done) {
isDevelopment = false;
gulp.series(
deleteBuild,
compileProject
)(done);
}
export function runDev (done) {
gulp.series(
deleteBuild,
compileProject,
startServer,
watchFiles
)(done);
}