-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
135 lines (117 loc) · 3.46 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
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
const sassGlob = require('gulp-sass-glob');
const groupMediaQueries = require('gulp-group-css-media-queries');
const cleanCSS = require('gulp-cleancss');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const sourcemaps = require('gulp-sourcemaps');
const replace = require('gulp-replace');
const del = require('del');
const plumber = require('gulp-plumber');
const browserSync = require('browser-sync').create();
const svgstore = require('gulp-svgstore');
const svgmin = require('gulp-svgmin');
const imagemin = require('gulp-imagemin');
const paths = {
src: './src/', // paths.src
build: './build/' // paths.build
};
function styles() {
return gulp.src(paths.src + 'scss/style.scss')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sassGlob())
.pipe(sass()) // { outputStyle: 'compressed' }
.pipe(groupMediaQueries())
.pipe(postcss([
autoprefixer({browsers: ['last 2 version']}),
]))
.pipe(cleanCSS())
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write('/'))
.pipe(gulp.dest(paths.build + 'css/'));
}
function svgSprite() {
return gulp.src(paths.src + 'svg/*.svg')
.pipe(svgmin(function (file) {
return {
plugins: [{
cleanupIDs: {
minify: true
}
}]
}
}))
.pipe(svgstore({ inlineSvg: true }))
.pipe(rename('sprite-svg.svg'))
.pipe(gulp.dest(paths.build + 'img/'));
}
function scripts() {
return gulp.src(paths.src + 'js/*.js')
.pipe(plumber())
.pipe(babel({
presets: ['env']
}))
.pipe(uglify())
.pipe(concat('script.min.js'))
.pipe(gulp.dest(paths.build + 'js/'))
}
function scriptsVendors() {
return gulp.src([
'node_modules/jquery/dist/jquery.min.js',
'node_modules/slick-carousel/slick/slick.min.js',
'node_modules/svg4everybody/dist/svg4everybody.min.js'
])
.pipe(concat('vendors.min.js'))
.pipe(gulp.dest(paths.build + 'js/'))
}
function htmls() {
return gulp.src(paths.src + '*.html')
.pipe(plumber())
.pipe(replace(/\n\s*<!--DEV[\s\S]+?-->/gm, ''))
.pipe(gulp.dest(paths.build));
}
function images() {
return gulp.src(paths.src + 'img/*.{jpg,jpeg,png,gif,svg}')
.pipe(imagemin()) // если картинок будет много, то и времени будет уходить много
.pipe(gulp.dest(paths.build + 'img/'));
}
function clean() {
return del('build/')
}
function watch() {
gulp.watch(paths.src + 'scss/*.scss', styles);
gulp.watch(paths.src + 'js/*.js', scripts);
gulp.watch(paths.src + '*.html', htmls);
}
function serve() {
browserSync.init({
server: {
baseDir: paths.build
}
});
browserSync.watch(paths.build + '**/*.*', browserSync.reload);
}
exports.styles = styles;
exports.scripts = scripts;
exports.scriptsVendors = scriptsVendors;
exports.htmls = htmls;
exports.images = images;
exports.svgSprite = svgSprite;
exports.clean = clean;
exports.watch = watch;
gulp.task('build', gulp.series(
clean,
gulp.parallel(styles, svgSprite, scripts, scriptsVendors, htmls, images)
));
gulp.task('default', gulp.series(
clean,
gulp.parallel(styles, svgSprite, scripts, scriptsVendors, htmls, images),
gulp.parallel(watch, serve)
));