-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
111 lines (94 loc) · 2.76 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
// Gulp dependencies
var gulp = require('gulp');
// Style dependencies
var sass = require('gulp-sass');
var cssnano = require('gulp-cssnano');
var autoprefixer = require('gulp-autoprefixer');
// JavaScript dependencies
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
// Images dependencies
var imagemin = require('gulp-imagemin');
// Other requires...
var useref = require('gulp-useref');
var gulpIf = require('gulp-if');
var del = require('del');
var runSequence = require('run-sequence');
var notify = require('gulp-notify');
var rev = require('gulp-rev');
var revReplace = require('gulp-rev-replace');
// Styles task
gulp.task('sass', function() {
return gulp.src('app/scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest('app/css'));
});
// Javascript task
var notifyJsHint = function (file) {
if (file.jshint.success) {
// Notify only on error
return false;
}
var errors = file.jshint.results.map(function (data) {
if (data.error) {
return '(' + data.error.line + ':' + data.error.character + ') ' + data.error.reason;
}
}).join('\n');
return file.relative + ' (' + file.jshint.results.length + ' errors)\n' + errors;
};
gulp.task('jshint', function() {
return gulp.src('./app/js/*.js')
.pipe(jshint())
.pipe(notify(notifyJsHint));
});
// Images task
gulp.task('images', function() {
return gulp.src('app/images/**/*.+(png|jpg|gif|svg)')
.pipe(imagemin())
.pipe(gulp.dest('dist/images'));
});
// Fonts task
gulp.task('fonts', function() {
return gulp.src('app/fonts/**/*')
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('clean:dist', function() {
return del.sync('dist');
});
gulp.task('useref', function() {
return gulp.src('app/*.html')
.pipe(useref())
// Minifies only if it's a JavaScript file
.pipe(gulpIf('*.js', uglify()))
// Minifies only if it's a CSS file
.pipe(gulpIf('*.css', cssnano()))
// Asset revisioning
.pipe(gulpIf('*.css', rev()))
.pipe(gulpIf('*.js', rev()))
.pipe(revReplace())
.pipe(gulp.dest('dist'));
});
// Extras
gulp.task('extras', function () {
return gulp.src(['app/robots.txt', 'app/favicon.ico', 'app/order.php'])
.pipe(gulp.dest('dist'));
});
// Builder
gulp.task('build', function (callback) {
runSequence('clean:dist',
['sass', 'useref', 'images', 'fonts', 'extras'],
callback
);
});
// Watcher
gulp.task('watch', function() {
gulp.watch('app/scss/**/*.scss', ['sass']);
gulp.watch('app/js/*.js', ['jshint']);
});
// Default
gulp.task('default', function (callback) {
runSequence(['jshint', 'sass', 'watch'],
callback
);
});