-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
137 lines (124 loc) · 3.15 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
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('gulp-cssnano');
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 browserSync = require('browser-sync').create();
const sequence = require('run-sequence');
gulp.task('html', () =>
gulp
.src('./src/*.html')
.pipe(rigger())
.pipe(
htmlmin({
collapseWhitespace: true,
}),
)
.pipe(gulp.dest('./build')),
);
gulp.task('styles', () =>
gulp
.src('./src/scss/styles.scss')
.pipe(plumber())
.pipe(
stylelint({
reporters: [{ formatter: 'string', console: true }],
}),
)
.pipe(sass())
.pipe(postcss([autoprefixer()]))
.pipe(gcmq())
.pipe(gulp.dest('./build/css'))
.pipe(cssnano())
.pipe(rename('styles.min.css'))
.pipe(gulp.dest('./build/css'))
.pipe(browserSync.stream()),
);
gulp.task('scripts', () =>
gulp
.src('./src/js/**/*.js')
.pipe(plumber())
.pipe(
babel({
presets: ['env'],
}),
)
.pipe(concat('scripts.js'))
.pipe(gulp.dest('./build/js'))
.pipe(uglify())
.pipe(rename('scripts.min.js'))
.pipe(gulp.dest('./build/js')),
);
gulp.task('svg-sprite', () =>
gulp
.src('./src/img/sprite/**/*.svg')
.pipe(
svgstore({
inlineSvg: true,
}),
)
.pipe(rename('sprite.svg'))
.pipe(gulp.dest('./build/img')),
);
gulp.task('images', () =>
gulp
.src(['./src/img/**/*.{png,jpg,jpeg,svg}', '!./src/img/sprite/**/*.*'])
.pipe(
imagemin([
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.svgo({
plugins: [{ removeViewBox: false }, { cleanupIDs: false }],
}),
]),
)
.pipe(gulp.dest('./build/img')),
);
gulp.task('fonts', () =>
gulp.src('./src/fonts/**/*.{woff,woff2}').pipe(gulp.dest('./build/fonts')),
);
gulp.task('watch', () => {
gulp.watch('src/**/*.html', ['html']).on('change', browserSync.reload);
gulp.watch('src/scss/**/*.scss', ['styles']);
gulp.watch('src/js/**/*.js', ['scripts']);
});
gulp.task('serve', ['styles'], () =>
browserSync.init({
server: './build',
notify: false,
open: true,
cors: true,
ui: false,
logPrefix: 'DevServer',
host: 'localhost',
port: 3000,
}),
);
gulp.task('del:build', () => del('./build'));
gulp.task('prepare', () => del(['**/.gitkeep', 'README.md', 'banner.png']));
gulp.task('build', cb =>
sequence(
'del:build',
'svg-sprite',
'images',
'fonts',
'styles',
'html',
'scripts',
cb,
),
);
gulp.task('start', cb => sequence('build', 'serve', 'watch'));