-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
88 lines (74 loc) · 2.2 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
var gulp = require('gulp'),
react = require('gulp-react'),
browserify = require('browserify'),
uglify = require('gulp-uglify'),
webserver = require('gulp-webserver')
plumber = require('gulp-plumber'),
gutil = require("gulp-util"),
source = require('vinyl-source-stream'),
watchify = require('watchify'),
notify = require('gulp-notify'),
reactify = require('reactify'),
streamify = require('gulp-streamify'),
es6ify = require('es6ify'),
//es6transpiler = require('gulp-es6-transpiler'),
debowerify = require('debowerify'),
gulpif = require('gulp-if');
var env = process.env.NODE_ENV || "dev";
var isProd = function() { return env === 'prod' };
var whenProd = function(act) { return gulpif(isProd(), act) };
function onError (error) {
console.log(error);
}
function handleError(task) {
return function(err) {
gutil.log(gutil.colors.red(err));
notify.onError(task + ' failed, check the logs..')(err);
};
}
function scripts(watch) {
console.log('scripts')
var bundler, rebundle;
bundler = browserify({
basedir: __dirname,
entries: './js/app.jsx',
debug: !isProd(),
cache: {}, // required for watchify
packageCache: {}, // required for watchify
fullPaths: watch // required to be true only for watchify
});
if(watch) {
bundler = watchify(bundler)
}
bundler.transform(reactify);
//bundler.transform(debowerify);
rebundle = function() {
var stream = bundler.bundle();
stream.on('error', handleError('Browserify'));
stream = stream.pipe(source('app.js'));
return stream
.pipe(whenProd(streamify(uglify())))
.pipe(gulpif(isProd(), gulp.dest('./dist/build/js'), gulp.dest('./build/js')))
};
bundler.on('update', rebundle);
return rebundle();
}
gulp.task('scripts', function() {
scripts(false)
});
gulp.task('webserver', function() {
gulp.src('.')
.pipe(webserver({
livereload: true,
directoryListing: false,
open: true
}));
});
gulp.task('watchScripts', function() {
return scripts(true);
});
gulp.task('prodenv', function() {
env = 'prod'
})
gulp.task('prod', ['prodenv','scripts'])
gulp.task('default', ['watchScripts', 'webserver']);