-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
135 lines (117 loc) · 3.34 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Include gulp
const gulp = require('gulp'),
uglify = require('gulp-uglify'),
autoprefixer = require('gulp-autoprefixer'),
plumber = require('gulp-plumber'),
cssnano = require('gulp-cssnano'),
sass = require('gulp-sass'),
notify = require('gulp-notify'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
changed = require('gulp-changed'),
parker = require('gulp-parker'),
fontgen = require('gulp-fontgen'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
hbsfy = require("hbsfy").configure({extensions: ["html"]}),
browserSync = require('browser-sync').create();
// Build javascript
gulp.task('scripts', function () {
return browserify('./src/js/app.js', {
debug: true
})
.transform(hbsfy)
.bundle()
.pipe(source('app.min.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./'))
.pipe(browserSync.stream());
});
// Handle styles
gulp.task('sass', function () {
return gulp.src('src/style/style.scss')
.pipe(changed('./'))
.pipe(plumber({
errorHandler: sassErrorAlert
}))
.pipe(sass())
.pipe(autoprefixer())
.pipe(cssnano())
.pipe(gulp.dest('./'))
.pipe(browserSync.stream());
});
// Browser Sync
gulp.task('browser-sync', function () {
browserSync.init({
proxy: 'localhost:8888',
open: false
});
});
// Images
gulp.task('images', () => {
return gulp.src('src/img/*')
.pipe(changed('img'))
.pipe(imagemin({
progressive: true,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngquant()]
}))
.pipe(gulp.dest('img'));
});
// Generate webfonts
gulp.task('font', function () {
return gulp.src("./src/fonts/*.{ttf,otf}")
.pipe(fontgen({
dest: "./fonts/"
}));
});
// Watch for changes in files
gulp.task('watch', function () {
// Watch .js files
gulp.watch('src/js/*.js', ['scripts']);
// Watch .html files
gulp.watch('*.html', browserSync.reload);
// Watch .scss files
gulp.watch('src/style/**/*.scss', ['sass']);
// Watch images
gulp.watch('src/img/*', ['images']);
// Watch fonts
gulp.watch('src/fonts/*.{ttf,otf}"', ['font']);
});
// Analyze CSS
gulp.task('parker', function () {
return gulp.src('./style.css')
.pipe(parker());
});
// Default Task
gulp.task('default', ['scripts', 'sass', 'watch', 'browser-sync', 'images']);
function sassErrorAlert(error) {
notify.onError({
title: 'SCSS Error',
message: error.message,
sound: 'Submarine'
})(error); //Error Notification
console.log(error.toString()); //Prints Error to Console
this.emit('end'); //End function
};
function handlebarsErrorAlert(error) {
notify.onError({
title: 'Handlebars Error',
message: error.message,
sound: 'Ping'
})(error); //Error Notification
console.log(error.toString()); //Prints Error to Console
this.emit('end'); //End function
};
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: "Compile Error",
message: "<%= error %>"
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
}