-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
121 lines (106 loc) · 2.92 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
'use strict';
const { src, dest, series, parallel, watch } = require('gulp');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const csso = require('gulp-csso');
const gcmq = require('gulp-group-css-media-queries');
const del = require('del');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const svgstore = require('gulp-svgstore');
const plumber = require('gulp-plumber');
const rigger = require('gulp-rigger');
const stylelint = require('gulp-stylelint');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const server = require('browser-sync').create();
function html() {
return src('src/*.html')
.pipe(rigger())
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest('build'));
}
function styles() {
return src('src/sass/styles.scss')
.pipe(plumber())
.pipe(
stylelint({
reporters: [{ formatter: 'string', console: true }],
}),
)
.pipe(sass())
.pipe(postcss([autoprefixer()]))
.pipe(gcmq())
.pipe(dest('build/css'))
.pipe(csso())
.pipe(rename('styles.min.css'))
.pipe(dest('build/css'))
.pipe(server.stream());
}
function scripts() {
return src('src/js/**/*.js')
.pipe(plumber())
.pipe(babel())
.pipe(concat('scripts.js'))
.pipe(dest('build/js'))
.pipe(uglify())
.pipe(rename('scripts.min.js'))
.pipe(dest('build/js'));
}
function sprite() {
return src('src/images/icons/icon-*.svg')
.pipe(svgstore({ inlineSvg: true }))
.pipe(rename('sprite.svg'))
.pipe(dest('build/images'));
}
function images() {
return src(['src/images/**/*.{png,jpg,jpeg,svg}', '!src/images/icons/**/*'])
.pipe(
imagemin([
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.svgo({
plugins: [{ removeViewBox: false }, { cleanupIDs: false }],
}),
]),
)
.pipe(dest('build/images'));
}
function fonts() {
return src('src/fonts/**/*').pipe(dest('build/fonts'));
}
function watcher(done) {
watch('src/**/*.html').on('change', series(html, server.reload));
watch('src/sass/**/*.scss').on('change', series(styles, server.reload));
watch('src/js/**/*.js').on('change', series(scripts, server.reload));
done();
}
function serve() {
return server.init({
server: 'build',
notify: false,
open: "local",
cors: true,
ui: false,
logPrefix: 'DevServer',
host: 'localhost',
port: 8080,
});
}
function clean() {
return del('./build');
}
function prepare() {
return del(['**/.gitkeep', 'README.md']);
}
const build = series(
clean,
parallel(sprite, images, fonts, html, styles, scripts),
);
const start = series(build, watcher, serve);
exports.prepare = prepare;
exports.build = build;
exports.start = start;