-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
111 lines (91 loc) · 2.55 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
'use strict';
var gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
livereload = require('gulp-livereload'),
sass = require('gulp-sass'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
gutil = require('gulp-util'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
_ = require('underscore'),
watchify = require('watchify'),
notify = require('gulp-notify');
var handleErrors = function() {
var args = Array.prototype.slice.call(arguments);
// Send error to notification center with gulp-notify
notify.onError({
title: "Compile Error",
message: "<%= error %>"
}).apply(this, args);
// Keep gulp from hanging on this task
this.emit('end');
};
var browserifyTask = function(devMode) {
var bundleConfig = {
entries: './public/js/app.js',
debug: true
};
if (devMode) {
_.extend(bundleConfig, watchify.args);
}
var b = browserify(bundleConfig);
var bundle = function() {
return b
.bundle()
.on('error', handleErrors)
// Use vinyl-source-stream to make the
// stream gulp compatible. Specify the
// desired output filename here.
.pipe(source('bundle.js'))
// Specify the output destination
.pipe(gulp.dest('./public/dist/'));
};
if(devMode) {
// Wrap with watchify and rebundle on changes
b = watchify(b);
// Rebundle on update
b.on('update', bundle);
} else {
// Sort out shared dependencies.
// b.require exposes modules externally
// if(bundleConfig.require) b.require(bundleConfig.require);
// // b.external excludes modules from the bundle, and expects
// // they'll be available externally
// if(bundleConfig.external) b.external(bundleConfig.external);
}
return bundle();
}
gulp.task('browserify', function () {
return browserifyTask();
});
gulp.task('watchify', function() {
return browserifyTask(true);
});
gulp.task('sass', function () {
gulp.src('./public/css/*.scss')
.pipe(sass())
.pipe(gulp.dest('./public/css'))
.pipe(livereload());
});
gulp.task('watch', ['watchify'], function() {
gulp.watch('./public/css/*.scss', ['sass']);
});
gulp.task('develop', function () {
livereload.listen();
nodemon({
script: 'bin/www',
ext: 'js jade coffee',
}).on('restart', function () {
setTimeout(function () {
livereload.changed(__dirname);
}, 500);
});
});
gulp.task('default', [
'sass',
'browserify',
'develop',
'watch'
]);