This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
90 lines (81 loc) · 3.08 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
var config = require('./gulpconfig.json'),
tasks = { js:[], less:[] };
var inquirer = require('inquirer');
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
gutil = require('gulp-util'),
notify = require("gulp-notify"),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
less = require('gulp-less'),
include = require('gulp-include'),
uglify = require('gulp-uglify');
var LessPluginAutoPrefix = require('less-plugin-autoprefix'),
groupmediaqueries = require('less-plugin-group-css-media-queries'),
autoprefix = new LessPluginAutoPrefix({ browsers: ['> 1%', 'last 2 versions', 'IE >= 8', 'Firefox ESR', 'Opera 12.1'] });
for (var group in config.build.less)
tasks.less.push('build:less:' + group);
for (var group in config.build.js)
tasks.js.push('build:js:' + group);
tasks.less.forEach(function(task){
gulp.task(task, function(done){
var group = task.split(':').pop();
for (var src in config.build.less[group]) {
var pipeline = gulp.src(src)
.pipe(plumber({
errorHandler: notify.onError({
title: 'Error running ' + task,
message: "<%= error.message %>"
})}
))
.pipe(less({
plugins: [groupmediaqueries, autoprefix]
}))
.pipe(rename(src.split('/').pop().replace('.less', '.css')))
;
config.build.less[group][src].forEach(function(path){
pipeline.pipe(gulp.dest(path))
})
return pipeline;
}
done();
});
});
gulp.task('build:less', gulp.parallel(tasks.less));
tasks.js.forEach(function(task){
gulp.task(task, function(done){
var group = task.split(':').pop();
for (var src in config.build.js[group]) {
var pipeline = gulp.src(src)
.pipe(plumber({
errorHandler: notify.onError({
title: 'Error running ' + task,
message: "<%= error.message %> in line no. <%= error.lineNumber %>"
})}
))
.pipe(include())
.pipe(rename(src.split('/').pop().replace('.js', '.js')))
;
config.build.js[group][src].forEach(function(path){
pipeline.pipe(gulp.dest(path))
})
return pipeline;
}
done();
});
});
gulp.task('build:js', gulp.parallel(tasks.js));
function watch(){
config.watch.forEach(function(obj){
for (var group in obj.build) {
gutil.log(gutil.colors.cyan('Watching ' + obj.files));
gulp.watch(obj.files, gulp.series(
'build:' + group + ':' + obj.build[group]
));
}
});
}
gulp.task('build', gulp.parallel(['build:less', 'build:js']));
gulp.task('build:all', gulp.parallel(['build:less', 'build:js']));
gulp.task('watch', watch);
gulp.task('init', gulp.series(['build:less', 'build:js']));