-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·157 lines (137 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
'use strict';
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const pug = require('gulp-pug');
const htmlBeautify = require('gulp-html-beautify');
const sass = require('gulp-sass');
const rename = require('gulp-rename');
const cssnano = require('gulp-cssnano');
const del = require('del');
const imageMin = require('gulp-imagemin');
const rigger = require('gulp-rigger');
const uglify = require('gulp-uglify');
const autoprefixer = require('gulp-autoprefixer');
const stripComments = require('gulp-strip-comments');
const path = {
dist: {
html: './dist',
styles: {
scss: './dist',
css: './dist',
},
js: './dist',
img: './dist/img',
upload: './dist/uploads',
fonts: './dist/fonts',
},
src: {
html: './src/html/views/**/*.pug',
styles: {
scss: './src/styles/main.scss',
css: './src/styles/vendor.css',
},
js: {
custom: './src/js/**/main.js',
vendor: './src/js/**/vendor.js'
},
img: './src/img/**/*.{png,gif,jpg,svg}',
upload: './src/uploads/**/*.*',
fonts: './src/fonts/**/*.*',
},
watch: {
html: './src/html/**/*.pug',
styles: {
scss: './src/styles/**/*.scss',
css: './src/styles/**/*.css',
},
js: './src/js/**/*.js',
img: './src/img/**/*.{png,gif,jpg,svg}',
upload: './src/uploads/**/*.*',
fonts: './src/fonts/**/*.*',
},
clean: './dist',
browserSyncWatch: 'dist/**/*.*',
};
// local server
gulp.task('serve', function () {
browserSync.init({
server: 'dist',
});
browserSync.watch(path.browserSyncWatch).on('change', browserSync.reload);
});
gulp.task('html', function () {
return gulp.src(path.src.html)
.pipe(pug())
.pipe(htmlBeautify())
.pipe(gulp.dest(path.dist.html));
});
// требуется удалять комментарии при сборке min.css
gulp.task('scss', function () {
return gulp.src(path.src.styles.scss)
.pipe(sass({
outputStyle: 'expanded',
indentWidth: 4,
}))
.pipe(autoprefixer({
browsers: ['last 8 versions', '> 1%', 'not dead', 'not ie < 11'],
cascade: true,
}))
.pipe(gulp.dest(path.dist.styles.scss));
});
gulp.task('css', function () {
return gulp.src(path.src.styles.css)
.pipe(rigger())
.pipe(gulp.dest(path.dist.styles.css));
});
gulp.task('styles', gulp.series(gulp.parallel('scss', 'css')));
gulp.task('js:custom', function () {
return gulp.src(path.src.js.custom)
.pipe(rigger())
.pipe(stripComments())
.pipe(gulp.dest(path.dist.js));
});
gulp.task('js:vendor', function () {
return gulp.src(path.src.js.vendor)
.pipe(rigger())
.pipe(gulp.dest(path.dist.js))
.pipe(uglify())
.pipe(stripComments())
.pipe(gulp.dest(path.dist.js));
});
gulp.task('js', gulp.series(gulp.parallel('js:custom', 'js:vendor')));
gulp.task('img', function () {
return gulp.src(path.src.img)
.pipe(imageMin({
optimizationLevel: 4,
progressive: true,
svgPlugins: [{
removeViewBox: false
}],
interlaced: true,
}))
.pipe(gulp.dest(path.dist.img));
});
gulp.task('fonts', function () {
return gulp.src(path.src.fonts)
.pipe(gulp.dest(path.dist.fonts));
});
gulp.task('uploads', function () {
return gulp.src(path.src.upload)
.pipe(gulp.dest(path.dist.upload));
});
gulp.task('watch', function () {
gulp.watch(path.watch.styles.css, gulp.series('css'));
gulp.watch(path.watch.styles.scss, gulp.series('scss'));
gulp.watch(path.watch.html, gulp.series('html'));
gulp.watch(path.watch.js, gulp.series('js'));
gulp.watch(path.watch.img, gulp.series('img'));
gulp.watch(path.watch.img, gulp.series('fonts'));
gulp.watch(path.watch.img, gulp.series('uploads'));
});
gulp.task('clean', function () {
return del(path.clean);
});
gulp.task('build',
gulp.series('clean',
gulp.parallel('html', 'styles', 'fonts', 'uploads', 'img', 'js')));
gulp.task('dev', gulp.series('build', gulp.parallel('watch', 'serve')));