Skip to content

Instantly share code, notes, and snippets.

@giobyte8
Forked from wesbos/gulpfile.js
Last active October 7, 2015 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save giobyte8/c3233e2e9fa4d3183a3b to your computer and use it in GitHub Desktop.
Save giobyte8/c3233e2e9fa4d3183a3b to your computer and use it in GitHub Desktop.
FAST Browserify + Reactify + Babelify
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var reactify = require('reactify');
var babelify = require('babelify');
var watchify = require('watchify');
var notify = require('gulp-notify');
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
}
function buildScript(file, watch) {
var props = {
entries: ['./scripts/' + file],
debug : true,
transform: [babelify, reactify]
};
// watchify() if watch requested, otherwise run browserify() once
var bundler = watch ? watchify(browserify(props)) : browserify(props);
function rebundle() {
var stream = bundler.bundle();
return stream
.on('error', handleErrors)
.pipe(source(file))
.pipe(gulp.dest('./build/'));
}
// listen for an update and run rebundle
bundler.on('update', function() {
rebundle();
gutil.log('Rebundle...');
});
// run it once the first time buildScript is called
return rebundle();
}
// run once
gulp.task('scripts', function() {
return buildScript('app.js', false);
});
// run 'scripts' task first, then watch for future changes
gulp.task('default', ['scripts'], function() {
return buildScript('app.js', true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment