-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
68 lines (54 loc) · 1.6 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
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var extend = require('lodash/object/extend');
var $ = require('gulp-load-plugins')();
var srcDir = './app/components/';
var buildDir = './public/';
gulp.task('js', function() {
return buildScript('app.jsx');
});
gulp.task('watch', function () {
buildScript('app.jsx', true);
});
gulp.task('default', ['js']);
function buildScript(file, watch) {
var props = extend({}, watchify.args, {
entries: [srcDir + file],
debug: true,
extensions: ['.js', '.jsx']
});
var bblfy = babelify.configure({
only: /(app)/
});
var brwsfy = browserify(props).transform(bblfy);
var bundler = watch ? watchify(brwsfy, {
ignoreWatch: true
}) : brwsfy;
function rebundle() {
return bundler.bundle()
.on('error', handleError)
.pipe(source('app.js'))
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest(buildDir + 'js/'));
}
bundler.on('update', rebundle);
bundler.on('log', $.util.log);
bundler.on('error', $.util.log);
return rebundle();
}
function handleError() {
$.util.beep();
$.notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, arguments);
// Keep gulp from hanging on this task
this.emit('end');
}