-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
39 lines (34 loc) · 1000 Bytes
/
gulpfile.babel.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
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import browserify from 'browserify';
import watchify from 'watchify';
import babel from 'babelify';
function compile(watch) {
var bundler = browserify('./src/index.jsx', {debug: true}).transform(babel);
function rebundle() {
console.log('-> bundling...');
bundler.bundle()
.on('error', function(err) {
console.error(err);
this.emit('end');
})
.on('end', function() {
console.log('done');
})
.pipe(source('build.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build'));
}
if (watch) {
bundler = watchify(bundler);
bundler.on('update', () => rebundle());
}
rebundle();
}
gulp.task('build', () => compile());
gulp.task('watch', () => compile(true));
gulp.task('default', ['watch']);