-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
162 lines (145 loc) · 3.84 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
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const mqpacker = require('css-mqpacker');
const debug = require('gulp-debug');
const del = require('del');
const browserSync = require('browser-sync').create();
const notify = require('gulp-notify');
const minify = require('gulp-csso');
const multipipe = require('multipipe');
const rename = require('gulp-rename');
const gulpStylelint = require('@ronilaukkarinen/gulp-stylelint');
const compress_images = require('compress-images');
gulp.task('styles', function () {
return multipipe(
gulp.src('src/styles/*.scss'),
sass().on('error', sass.logError),
postcss([
autoprefixer(),
mqpacker({
sort: true,
}),
]),
gulp.dest('build/styles'),
minify(),
rename('style-min.css'),
debug({ title: 'min-css' }),
gulp.dest('build/styles')
).on(
'error',
notify.onError(function (err) {
return {
title: 'Styles',
message: err.message,
};
})
);
});
// sass lint ftw(for better coding practices)
gulp.task('lint-css', function () {
return gulp.src('src/styles/*.scss').pipe(
gulpStylelint({
reporters: [{ formatter: 'string', console: true }],
debug: true,
failAfterError: false,
})
);
});
gulp.task('min-js', function () {
return multipipe(gulp.src('src/js/*.js'), gulp.dest('build/js'));
});
gulp.task('clean', function () {
return del('build');
});
gulp.task('images', function () {
return gulp.src('src/img/*').pipe(gulp.dest('build/img'));
});
gulp.task('fonts', function () {
return gulp.src('src/fonts/*').pipe(gulp.dest('build/fonts'));
});
gulp.task('img-compress', async function () {
return await compress_images(
'src/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}',
'build/',
{
compress_force: false,
statistic: true,
autoupdate: true,
},
false,
{
jpg: {
engine: 'mozjpeg',
command: ['-quality', '75'],
},
},
{ png: { engine: 'pngquant', command: ['--quality=30-70', '-o'] } },
{ svg: { engine: 'svgo', command: '--multipass' } },
{
gif: {
engine: 'gifsicle',
command: ['--colors', '64', '--use-col=web'],
},
},
function (err, completed) {
if (err !== null) {
if (err.engine === 'jpegRecompress') {
compress_images(
err.input,
err.output,
{
compress_force: false,
statistic: true,
autoupdate: true,
},
false,
{ jpg: { engine: 'mozjpeg', command: ['-quality', '60'] } },
{ png: { engine: false, command: false } },
{ svg: { engine: false, command: false } },
{ gif: { engine: false, command: false } }
);
}
}
}
);
});
gulp.task('html', function () {
return multipipe(
gulp.src('src/html/*.html', { since: gulp.lastRun('html') }),
debug({ title: 'html' }),
gulp.dest('build')
).on(
'error',
notify.onError(function (err) {
return {
title: 'html',
message: err.message,
};
})
);
});
gulp.task(
'build',
gulp.series(
'clean',
gulp.parallel('html', 'lint-css', 'styles', 'min-js'),
'images',
'fonts'
)
);
gulp.task('watch', function () {
gulp.watch('src/html/*.html', gulp.series('html'));
gulp.watch('src/js/*.js', gulp.series('min-js'));
gulp.watch('src/styles/**/*.*', gulp.series('styles', 'lint-css'));
gulp.watch('src/img/**/*.*', gulp.series('images'));
});
gulp.task('serve', function () {
browserSync.init({
server: 'build',
});
browserSync.watch('build/**/*.*').on('change', browserSync.reload);
});
gulp.task('dev', gulp.series('build', gulp.parallel('watch', 'serve')));