-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
129 lines (113 loc) · 3.2 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
const {src, dest, watch, parallel, series} = require('gulp');
const scss = require('gulp-sass')(require('sass'));
const concat = require('gulp-concat');
const uglify = require('gulp-uglify-es').default;
const browserSync = require('browser-sync').create();
const autoprefixer = require('gulp-autoprefixer');
const clean = require('gulp-clean');
const avif = require('gulp-avif');
const webp = require('gulp-webp');
const imagemin = require('gulp-imagemin');
const newer = require('gulp-newer');
const fonter = require('gulp-fonter');
const ttf2woff2 = require('gulp-ttf2woff2');
const svgSprite = require('gulp-svg-sprite');
const include = require('gulp-include');
function pages() {
return src('app/pages/*.html')
.pipe(include({
includePaths: 'app/components'
}))
.pipe(dest('app'))
.pipe(browserSync.stream())
}
function fonts() {
return src('app/fonts/src/*.*')
.pipe(fonter({
formats: ['woff', 'ttf']
}))
.pipe(src('app/fonts/*.ttf'))
.pipe(ttf2woff2())
.pipe(dest('app/fonts'))
}
function images(){
return src(['app/images/src/**/*.*', '!app/images/src/**/*.svg'])
.pipe(newer('app/images'))
.pipe(avif({ quality : 50}))
.pipe(src('app/images/src/**/*.*'))
.pipe(newer('app/images'))
.pipe(webp())
.pipe(src('app/images/src/**/*.*'))
.pipe(newer('app/images'))
.pipe(imagemin())
.pipe(dest('app/images'))
}
function sprite () {
return src('app/images/**/*.svg')
.pipe(svgSprite({
mode: {
stack: {
sprite: '../sprite.svg',
example: true
}
}
}))
.pipe(dest('app/images'))
}
function scripts() {
return src([
'node_modules/swiper/swiper-bundle.js',
'app/js/main.js',
])
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(dest('app/js'))
.pipe(browserSync.stream())
}
function styles() {
return src('app/scss/style.scss')
.pipe(autoprefixer({ overrideBrowserslist: ['last 10 version']}))
.pipe(concat('style.min.css'))
.pipe(scss({ outputStyle: 'compressed' }))
.pipe(dest('app/css'))
.pipe(browserSync.stream())
}
function watching() {
browserSync.init({
server: {
baseDir: "app/"
}
});
watch(["app/scss/style.scss", "app/scss/media.scss"], styles);
watch(['app/images/src'], images)
watch(['app/js/main.js'], scripts)
watch(['app/components/*', 'app/pages/*'], pages)
watch(['app/*.html']).on('change', browserSync.reload);
}
function cleanDist() {
return src('dist')
.pipe(clean())
}
function building() {
return src([
'app/css/style.min.css',
'!app/images/**/*.html',
'app/images/*.*',
'!app/images/*.svg',
'app/images/sprite.svg',
'app/fonts/*.*',
'app/js/main.min.js',
'app/**/*.html'
], {base : 'app'})
.pipe(dest('dist'))
}
exports.styles = styles;
exports.images = images;
exports.fonts = fonts;
exports.pages = pages;
exports.building = building;
exports.sprite = sprite;
exports.scripts = scripts;
exports.watching = watching;
exports.build = series(cleanDist, building);
exports.default = parallel(styles, images, scripts, pages, watching);