-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gulpfile.js
108 lines (96 loc) · 2.32 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
/**
* timbr.dev Gulp template.
*
* Template last updated: 2021-06-17.
* File last updated: 2022-01-12.
*/
/**
* Directories.
*/
var dir = {
input: {
less: 'less',
},
output: {
less: 'css',
},
};
/**
* Packages.
*/
var gulp = require( 'gulp' );
var autoprefixer = require( 'gulp-autoprefixer' );
var cleancss = require( 'gulp-clean-css' );
var filter = require( 'gulp-filter' );
var notify = require( 'gulp-notify' );
var plumber = require( 'gulp-plumber' );
var rename = require( 'gulp-rename' );
var log = require( 'fancy-log' );
// less
var less = require( 'gulp-less' );
/**
* Error handlers.
*/
var onErrorLess = function ( err ) {
log( '------------------' );
log( 'Less has an error!' );
log( '------------------' );
notify.onError({
title: "Error in "+err.filename.replace( /^.*[\\\/]/, '' )+" on line "+err.line,
message: err.extract,
appID: "Gulp",
})( err );
log( '------------------' );
this.emit('end');
};
/**
* Procedures.
*/
var app = [];
app.processLess = function ( args ) {
// use all the files
return gulp.src( args.inputFiles )
// catch errors
.pipe( plumber( { errorHandler: onErrorLess } ) )
// compile the less to css
.pipe( less() )
// autoprefix the css
.pipe( autoprefixer() )
// minify the css
.pipe( cleancss( { keepSpecialComments: 0 } ) )
// name the output file
.pipe( rename( args.outputFile ) )
// place the output file
.pipe( gulp.dest( args.outputDir ) );
};
/**
* Tasks: Less.
*/
gulp.task( 'less_theme', function ( done ) {
app.processLess({
'name' : 'theme less',
'inputFiles' : [ dir.input.less+'/theme.less' ],
'outputDir' : dir.output.less,
'outputFile' : 'theme.min.css',
});
done();
});
/**
* Task: Watch.
*/
gulp.task( 'watch', function () {
// Less
gulp.watch( dir.input.less+'/theme.less', gulp.parallel( 'less_theme' ) );
// notify
gulp.src( 'node_modules/gulp-notify/test/fixtures/1.txt' ).pipe( notify({
title: "Gulp watch is ready.",
message: " ",
appID: "Gulp",
}));
});
/**
* Task: Default.
*/
gulp.task( 'default', gulp.parallel(
'less_theme',
));