Skip to content

Instantly share code, notes, and snippets.

@TheHanna
Forked from danharper/gulpfile.js
Last active April 27, 2017 21:47
Show Gist options
  • Save TheHanna/29b5e9e44186e75214ba1334da6118df to your computer and use it in GitHub Desktop.
Save TheHanna/29b5e9e44186e75214ba1334da6118df to your computer and use it in GitHub Desktop.
New ES6 project with Babel, Browserify & Gulp (ES6 Gulpfile w/ glob for Windows compatibility)
const gulp = require('gulp');
const glob = require('glob');
const sourcemaps = require('gulp-sourcemaps');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const browserify = require('browserify');
const watchify = require('watchify');
const babel = require('babelify');
function compile(watch) {
let bundler = watchify(browserify({ entries: glob.sync('./js/*.js'), debug: true }).transform(babel));
function rebundle() {
bundler.bundle()
.on('error', (err) => { console.error(err); this.emit('end'); })
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./'));
}
if (watch) {
bundler.on('update', function() {
console.log('-> bundling...');
rebundle();
});
}
rebundle();
}
function watch() {
return compile(true);
};
gulp.task('build', () => compile());
gulp.task('watch', () => watch());
gulp.task('default', ['watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment