-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
65 lines (53 loc) · 1.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
var gulp = require('gulp');
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var browserify = require('browserify');
var es6ify = require('es6ify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var envify = require('envify');
var reactify = require('reactify');
var scriptDir = 'client/scripts/';
var destDir = 'client/dist/';
gulp.task('client-server', function() {
connect.server({
root: './client',
port: 4000,
livereload: true
});
});
var compileScripts = function(opts) {
var entryFile = scriptDir + 'app.js';
var bundles = [ es6ify.runtime, entryFile ];
var browserifyOptions = {
// Required watchify args
cache: {},
packageCache: {},
fullPaths: true,
// Browserify options
debug: opts.debug === true
};
es6ify.traceurOverrides = { experimental: true, blockBinding: true };
var bundler = browserify(bundles, browserifyOptions);
var bundle = function() {
gutil.log('Transforming scripts from JSX and ES6 to ES5...');
return bundler
.bundle()
.on('error', gutil.log)
.pipe(source('app.js'))
.pipe(gulp.dest(destDir))
.pipe(connect.reload());
};
bundler
.transform(envify)
.transform(reactify)
.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/));
if (opts.watch) {
bundler = watchify(bundler).on('update', bundle);
}
return bundle();
};
gulp.task('client', ['client-server'], function () {
return compileScripts({ watch: true, debug: true });
});
gulp.task('default', ['client']);