-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (81 loc) · 2.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
let gulp = require('gulp'),
gutil = require('gulp-util'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename');
let less = require('gulp-less'),
LessAutoprefix = require('less-plugin-autoprefix'),
autoprefix = new LessAutoprefix({browsers: ['last 3 versions']}),
LessCleanCSS = require('less-plugin-clean-css'),
clean_css = new LessCleanCSS({advanced: true});
////////////////
// WATCHERS //
////////////////
gulp.task('watch', function () {
gulp.watch(['./src/**/*.less', './src/assets/less/includes.less'], ['less:components']);
gutil.log(gutil.colors.yellow('Watching...'));
});
/////////////////////
// TASK WRAPPERS //
/////////////////////
gulp.task('less:components', function () {
let source = ['./src/**/*.less', '!./src/assets/**/*.less'];
let dest = './src/';
runLess(source, dest, 'less:components');
});
/////////////////
// LESS TASK //
/////////////////
let less_runners = [];
function runLess(source, dest, task_name) {
if (less_runners.indexOf(task_name) === -1) {
less_runners.push(task_name);
log('start', task_name);
let start = Date.now();
gulp.src(source)
.pipe(plumber(error_config))
.pipe(less({
plugins: [autoprefix, clean_css]
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(dest))
.on('end', function () {
log('finish', task_name, Date.now() - start);
less_runners.splice(less_runners.indexOf(task_name), 1);
});
}
}
////////////
// LOG //
////////////
function log(type, task_name, duration) {
if (typeof(duration) === 'undefined') {
duration = 0;
}
switch (type) {
case 'start':
gutil.log('Starting ' + gutil.colors.cyan(task_name) + ' ...');
break;
case 'finish':
gutil.log('Finished ' + gutil.colors.green(task_name) + ' after ' + gutil.colors.magenta(duration + ' ms'));
break;
}
}
/////////////////////
// ERROR HANDLER //
/////////////////////
let error_config = {
errorHandler: notify.onError({
title: 'Gulp',
message: 'Error: <%= error.message %>',
sound: 'beep'
})
};
////////////////////
// DEFAULT TASK //
////////////////////
gulp.task('default', function () {
gulp.start('watch');
});