-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
61 lines (51 loc) · 1.42 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
var babelify = require('babelify')
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var clean = require('gulp-clean');
var gulp = require('gulp');
var gutil = require('gulp-util');
var notify = require("gulp-notify");
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var entryFile = './src/app.js',
buildDir = './build/scripts/';
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: "Compile Error",
message: "<%= error.message %>"
}).apply(this, args);
this.emit('end');
}
function buildScript(watch) {
var props = {
entries: [ entryFile ],
debug: true,
cache: {},
packageCache: {}
};
var bundler = watch ? watchify(browserify(props)) : browserify(props);
bundler.transform(babelify, { presets: ['react'] });
function rebundle() {
var stream = bundler.bundle();
return stream.on('error', handleErrors)
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(gulp.dest(buildDir));
}
bundler.on('update', function() {
rebundle();
gutil.log('Rebundling Complete!');
});
return rebundle();
}
gulp.task('clean', function() {
return gulp.src(buildDir + '*.js', { read: false })
.pipe(clean());
});
gulp.task('build', ['clean'], function() {
return buildScript(false);
});
gulp.task('default', ['build'], function() {
return buildScript(true);
});