-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
60 lines (50 loc) · 1.5 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
const gulp = require('gulp');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const notify = require('gulp-notify');
function handleErrors() {
const args = Array.prototype.slice.call(arguments);
notify.onError({
title : 'Compile Error',
message : '<%= error.message %>'
}).apply(this, args);
//console.log('Compile error: ', args);
this.emit('end'); //keeps gulp from hanging on this task
}
function buildScript(file, watch) {
const props = {
entries : ['./client/react/' + file],
debug : true,
transform : babelify.configure({
presets: ["react", "es2015"]
})
};
//watchify if watch set to true. otherwise browserify once
const bundler = browserify(props);
function rebundle(){
var stream = bundler.bundle();
return stream
.on('error', handleErrors)
.pipe(source('bundle.js'))
.pipe(gulp.dest('./client/build/'));
}
bundler.on('update', function() {
const updateStart = Date.now();
rebundle();
console.log('Updated!', (Date.now() - updateStart) + 'ms');
});
// run it once the first time buildScript is called
return rebundle();
}
// run once
gulp.task('scripts', function() {
return buildScript('main.jsx', false);
});
//run nodemon
gulp.task('start', function() {
});
// run 'scripts' task first, then watch for future changes
gulp.task('default', ['scripts', 'start'], function() {
return buildScript('main.jsx', true);
});