forked from stefanomarra/jquery-roadmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (94 loc) · 2.74 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
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
autoprefixer = require('autoprefixer'),
babel = require('gulp-babel'),
cleancss = require('gulp-clean-css'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
postcss = require('gulp-postcss'),
flexibility = require('postcss-flexibility');
var SRC = {
js: 'src/*.js',
css: 'src/*.scss'
};
/* Directories */
var DIRS = {
src: './src',
dest: './dist'
};
/**
* Error reporting helper function.
* Code from https://github.com/brendanfalkowski
*
* @param err
*/
var errorReport = function(err) {
var lineNumber = (err.lineNumber) ? 'LINE ' + err.lineNumber + ' -- ' : '';
notify({
title: 'Task failed [' + err.plugin + ']',
message: lineNumber + 'See console.',
sound: 'Basso'
}).write(err);
gutil.beep();
// Report the error on the console
var report = '';
var chalk = gutil.colors.bgMagenta.white;
report += chalk('TASK:') + ' [' + err.plugin + ']\n';
report += chalk('ISSUE:') + ' ' + err.message + '\n';
if (err.lineNumber) { report += chalk('LINE:') + ' ' + err.lineNumber + '\n'; }
if (err.fileName) { report += chalk('FILE:') + ' ' + err.fileName + '\n'; }
console.log(report);
// Prevent the 'watch' task from stopping
this.emit('end');
};
// Lint JS
gulp.task('lint:js', function() {
return gulp.src(SRC_JS)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
// Build CSS
gulp.task('build:css', function() {
return gulp.src(SRC.css)
.pipe(sass({
compress: true
}))
.pipe(postcss([autoprefixer({
browsers: [
"Android 2.3",
"Android >= 4",
"Chrome >= 20",
"Firefox >= 24",
"Explorer >= 8",
"iOS >= 6",
"Opera >= 12",
"Safari >= 6"
]
}), flexibility()]))
.pipe(cleancss())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(DIRS.dest));
});
gulp.task('build:js', function() {
return gulp.src(SRC.js)
.pipe(babel())
.pipe(gulp.dest(DIRS.dest))
.pipe(uglify({
preserveComments:'license'
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(DIRS.dest));
});
// WATCH for file changes and rerun the task
gulp.task('watch', function() {
gulp.watch(SRC.js, gulp.series('build:js'));
gulp.watch(SRC.css, gulp.series('build:css'));
});
// DEFAULT task
gulp.task('default', gulp.series('build:js', 'build:css'));