-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
executable file
·116 lines (103 loc) · 3.13 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
"use strict";
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
watch = require('gulp-watch'),
clean = require('gulp-clean'),
gutil = require('gulp-util'),
minify = require('gulp-minify-css'),
merge = require('merge-stream'),
htmlmin = require('gulp-htmlmin'),
imagemin = require('gulp-imagemin'),
browserSync = require('browser-sync').create(),
reload = browserSync.reload,
config = require('./gulp/config');
gulp.task('clean', function (done) {
gulp.src(['dist'], {
read: false
})
.pipe(clean())
.on('end', function () {
gutil.log('All cleaned!');
});
done();
});
gulp.task('clean-js', function (done) {
gulp.src(config.files.js, {
read: false
})
.pipe(clean());
done();
});
gulp.task('clean-css', function (done) {
gulp.src(config.files.css, {
read: false
})
.pipe(clean());
done();
});
gulp.task('concat-minify-js', function (done) {
gulp.src(config.vendors.js)
.pipe(concat('build'))
.pipe(config.env === 'production' ? uglify() : gutil.noop())
.pipe(rename({
extname: ".min.js"
}))
.pipe(gulp.dest(config.dirs.js))
.pipe(reload({stream: true}))
.on('end', function () {
gutil.log('Scripts concatenated and merged!');
});
done();
});
gulp.task('concat-minify-css', function (done) {
var sassStream = gulp.src(config.components.sass)
.pipe(sass({
errLogToConsole: true
}));
var cssStream = gulp.src(config.vendors.css);
var mergedStream = merge(sassStream, cssStream)
.pipe(concat('build.min.css'))
.pipe(config.env === 'production' ? minify() : gutil.noop())
.pipe(gulp.dest(config.dirs.css))
.pipe(reload({stream: true}))
.on('end', function () {
gutil.log('Styles concatenated and merged!');
});
done();
return mergedStream;
});
gulp.task('concat-minify-html', function (done) {
gulp.src(config.components.html)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(config.dirs.html))
.pipe(reload({stream: true}))
.on('end', function () {
gutil.log('HTML concatenated and merged!');
});
done();
});
gulp.task('compress-images', function (done) {
gulp.src(config.components.img)
.pipe(imagemin())
.pipe(gulp.dest(config.dirs.img));
done();
});
gulp.task('watch', function (done) {
browserSync.init({
server: {
baseDir: './'
},
browser: []
});
gulp.watch('./src/scss/**/*.scss', gulp.series('concat-minify-css'));
gulp.watch('./assets/js/*.js', gulp.series('concat-minify-js'));
gulp.watch('*.html', gulp.series('concat-minify-html'));
gulp.watch('./assets/img/*', gulp.series('compress-images'));
done();
});
gulp.task('default', gulp.series('concat-minify-css',
gulp.parallel('concat-minify-js', 'concat-minify-html', 'compress-images', 'watch')
));