-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.mjs
163 lines (144 loc) · 3.47 KB
/
gulpfile.mjs
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
/* eslint-disable import/no-extraneous-dependencies */
import gulp from 'gulp';
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
import stylelint from '@ronilaukkarinen/gulp-stylelint';
import pug from 'gulp-pug';
import pugLinter from 'gulp-pug-linter';
import imagemin from 'gulp-imagemin';
import { deleteAsync } from 'del';
import browserSyncJob from 'browser-sync';
import autoprefixer from 'autoprefixer';
import postcss from 'gulp-postcss';
import eslint from 'gulp-eslint';
const browserSync = browserSyncJob.create();
const sass = gulpSass(dartSass);
function imageMin(cb) {
gulp.src(['src/img/**/*', 'src/apple-touch-icon.png'], {
since: gulp.lastRun(imageMin),
base: 'src',
})
.pipe(imagemin())
.pipe(gulp.dest('build'))
.pipe(browserSync.stream());
cb();
}
function clean() {
return deleteAsync(['build/']);
}
function copyMisc() {
return gulp.src(['src/favicon.ico', 'src/manifest.webmanifest'])
.pipe(gulp.dest('build/'))
.pipe(browserSync.stream());
}
function copyFonts() {
return gulp.src('src/fonts/**/*')
.pipe(gulp.dest('build/fonts/'))
.pipe(browserSync.stream());
}
function copyJS() {
return gulp.src('src/js/**/*')
.pipe(gulp.dest('build/js/'))
.pipe(browserSync.stream());
}
function lintJS() {
return gulp.src('src/js/')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function browsersync() {
browserSync.init({
server: 'build/',
serveStaticOptions: {
extensions: ['html'],
},
open: false,
});
}
function lintSass() {
return gulp.src('src/scss/**/*.scss')
.pipe(stylelint({
configFile: './.stylelintrc.js',
failAfterError: true,
reporters: [
{ formatter: 'string', console: true },
],
fix: true,
}));
}
function compileSass() {
return gulp.src('src/scss/**/*.scss')
.pipe(sass({
outputStyle: 'compressed', // compressed | expanded
}))
.pipe(gulp.dest('build/css/'))
.pipe(browserSync.stream());
}
function postCSS() {
return gulp.src('build/css/*.css')
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest('build/css'))
.pipe(browserSync.stream());
}
function lintPug() {
return gulp.src('src/pug/**/*.pug')
.pipe(pugLinter({
reporter: 'puglint-stylish',
failAfterError: true,
}));
}
function compilePug() {
return gulp.src('src/pug/pages/*.pug')
.pipe(pug({
pretty: false, // true | false
doctype: 'html',
}))
.pipe(gulp.dest('build/'))
.pipe(browserSync.stream());
}
function watcher() {
gulp.watch('src/scss/**/*.scss', gulp.series(lintSass, compileSass));
gulp.watch('src/pug/**/*.pug', gulp.series(lintPug, compilePug));
gulp.watch(['src/img/**/*', 'src/apple-touch-icon.png'], imageMin);
gulp.watch(['src/favicon.ico', 'src/manifest.webmanifest'], copyMisc);
gulp.watch('src/fonts/**/*', copyFonts);
gulp.watch('src/js/**/*', gulp.series(lintJS, copyJS));
}
gulp.task(
'server',
gulp.series(
browsersync,
),
);
gulp.task(
'copy',
gulp.series(
copyFonts,
copyMisc,
),
);
gulp.task(
'build',
gulp.series(
clean,
gulp.series(lintPug, compilePug),
gulp.series(lintSass, compileSass, postCSS),
gulp.series(lintJS, copyJS),
'copy',
imageMin,
),
);
gulp.task(
'default',
gulp.parallel(
clean,
gulp.series(lintPug, compilePug),
gulp.series(lintSass, compileSass),
gulp.series(lintJS, copyJS),
'copy',
imageMin,
browsersync,
watcher,
),
);