-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
84 lines (64 loc) · 2.1 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var streamqueue = require('streamqueue');
var uglify = require('gulp-uglify');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();
var browserify = require('browserify');
var babel = require('gulp-babel');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var es = require('event-stream');
var reactComponents = [
'src/GrigoryGraborenko/RecursiveAdmin/Resources/js/react/admin.jsx'
];
gulp.task('default', function () {
gulp.start('all');
});
function jsx(watch) {
function getBundleFn(bundler, filename) {
return function() {
console.log('building: ' + filename);
return bundler
.bundle()
.on('error', function(err) {
console.log(err.message);
this.emit('end');
})
.pipe(source(filename)) //convert file stream to vinyl fs format
.pipe(rename(function(path) {
path.dirname += '/dist'; //place bundle in dist subdir with .bundle suffix
path.extname = '.js';
}))
.pipe(gulp.dest('.'));
}
}
var bundleTasks = reactComponents.map(function(entry) {
var bundler = browserify({entries : entry })
.transform(babelify, {presets: ["es2015", "react"]});
if(watch) {
bundler = watchify(bundler, {poll: true});
}
var bundleFn = getBundleFn(bundler, entry);
bundler.on('update', bundleFn);
bundler.on('log', console.log);
return bundleFn();
});
return es.merge.apply(null, bundleTasks);
}
gulp.task('jsx', function() {
return jsx(false);
});
gulp.task('jsx-watch', function() {
return jsx(true);
});
// Do common tasks
gulp.task('all', function() {
gulp.start('jsx');
});
// Watch changing files and update as necessary.
gulp.task('watch', function () {
gulp.start('jsx-watch');
});