Skip to content

Instantly share code, notes, and snippets.

@madhums madhums/gulpfile.js forked from danharper/gulpfile.js
Created Jul 18, 2015

Embed
What would you like to do?
ES6 project with Babel, Browserify & Gulp
'use strict';
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile (watch) {
var filename = watch ? 'app-dev.js' : 'app.js';
var bundler = browserify('./app.js', { debug: true }).transform(babel)
var watcher = watch ? watchify(bundler) : '';
function rebundle () {
return bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source(filename))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
}
if (watch) {
watcher.on('update', function () {
console.log('-> bundling...');
rebundle();
});
}
return rebundle();
}
function watch() {
return compile(true);
};
gulp.task('build', function () { return compile(); });
gulp.task('watch', function () { return watch(); });
gulp.task('default', ['watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.