-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
164 lines (148 loc) · 4.28 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
import {src, dest, watch, series, parallel} from 'gulp';
import {deleteAsync} from 'del';
import postcss from 'gulp-postcss';
import cssnano from 'cssnano';
import atImport from 'postcss-import';
import purgecss from 'gulp-purgecss';
import {stream as critical} from 'critical';
import compiler from 'webpack';
import webpack from 'webpack-stream';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import svgsprite from 'gulp-svg-sprite';
import imagemin, {gifsicle, mozjpeg, optipng, svgo} from 'gulp-imagemin';
import webp from 'gulp-webp';
import hb from 'gulp-hb';
import ext from 'gulp-ext-replace'
import sitemap from 'gulp-sitemap';
import browsersync from 'browser-sync';
export const clean = () => deleteAsync('dist/');
export function root() {
return src(['src/root/*', 'src/root/.*'], {encoding: false})
.pipe(dest('dist/'))
.pipe(browsersync.stream());
}
export function fonts() {
return src('src/fonts/*', {encoding: false})
.pipe(dest('dist/fonts/'))
.pipe(browsersync.stream());
}
export function videos() {
return src('src/videos/*', {encoding: false})
.pipe(dest('dist/videos/'))
.pipe(browsersync.stream());
}
export function scripts() {
return src('src/js/main.js', {encoding: false})
.pipe(webpack({}, compiler, function() {}))
.pipe(uglify())
.pipe(concat('main.js'))
.pipe(dest('dist/js/'))
.pipe(browsersync.stream());
}
export function styles() {
return src('src/css/main.css', {encoding: false})
.pipe(postcss([atImport, cssnano()]))
.pipe(purgecss({
content: ['dist/*.html']
}))
.pipe(dest('dist/css/'))
.pipe(browsersync.stream());
}
export function criticalStyles() {
return src('dist/**/*.html', {encoding: false})
.pipe(
critical({
base: 'dist/',
inline: true,
css: 'dist/css/main.css'
})
)
.pipe(dest('dist/'))
.pipe(browsersync.stream());
}
export function sprite() {
return src('src/sprite/**/**/*.svg', {encoding: false})
.pipe(svgsprite({
shape: { spacing: { padding: 5 } },
mode: { symbol: true },
svg: { xmlDeclaration: false, doctypeDeclaration: false, namespaceIDs: false, namespaceClassnames: false }
}))
.pipe(concat('sprite.hbs'))
.pipe(dest('src/html/partials/global/'))
.pipe(browsersync.stream());
}
export function images() {
src('src/img/**/**/*[.jpg|.gif|.png]', {encoding: false})
.pipe(imagemin([
gifsicle({interlaced: true}),
mozjpeg({quality: 75, progressive: true}),
optipng({optimizationLevel: 5}),
]))
.pipe(webp())
.pipe(dest('dist/img/'))
.pipe(browsersync.stream());
return src('src/img/**/**/*.svg')
.pipe(imagemin([
svgo({
plugins: [
{
name: 'removeViewBox',
active: true
},
{
name: 'cleanupIDs',
active: true
},
{
name: 'collapseGroups',
active: true
}
]
})
]))
.pipe(dest('dist/img/'))
.pipe(browsersync.stream());
}
export function html() {
return src('src/html/*.hbs', {encoding: false})
.pipe(hb().partials('src/html/partials/**/*.hbs'))
.pipe(ext('.html'))
.pipe(dest('dist/'))
.pipe(browsersync.stream());
}
export function sitemaps() {
return src('dist/*.html', {
encoding: false,
read: false
})
.pipe(sitemap({
siteUrl: 'localhost',
fileName: 'sitemap.xml',
changefreq: 'weekly',
priority: function(siteUrl, loc, entry) {
return loc.split('/').length === 0 ? 1 : 0.5;
}
}))
.pipe(dest('dist/'))
.pipe(browsersync.stream());
}
export function browserSync(done) {
browsersync.init({server: {baseDir: "dist"}, port: 3000, open: false});
done();
}
export function browserSyncReload(done) {
browsersync.reload();
done();
}
function watchFiles() {
watch('src/js/**/*.js', scripts);
watch('src/sprite/**/*.svg', sprite);
watch(['src/html/**/*.hbs', 'src/css/**/*.css'], htmlBuild);
watch('src/img/**/*', images);
watch('src/root/**/*', root);
}
const htmlBuild = series(html, styles, criticalStyles, sitemaps);
export const build = series(clean, parallel(root, fonts, sprite, images, videos, scripts), htmlBuild);
const watchSrc = series(build, browserSync, watchFiles);
export default watchSrc;