js-step-system
Version:
45 lines (36 loc) • 1.09 kB
JavaScript
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 bundler = browserify('./example/app.js', { debug: true }).transform(babel);
if (watch) {
bundler = watchify(bundler);
}
function rebundle() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./example/dist'));
}
if (watch) {
bundler.on('update', function() {
console.log('-> Bundling...');
rebundle();
console.log('-> Done.');
});
}
rebundle();
}
function watch() {
return compile(true);
};
gulp.task('build', function() { return compile(); });
gulp.task('watch', function() { return watch(); });
gulp.task('default', ['watch']);