Skip to content

Instantly share code, notes, and snippets.

@andrewrocco
Last active February 18, 2016 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewrocco/7bd5beb3555cabe86a8c to your computer and use it in GitHub Desktop.
Save andrewrocco/7bd5beb3555cabe86a8c to your computer and use it in GitHub Desktop.
A sample React gulpfile
// gulpfile.js
var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var babelify = require('babelify');
var watchify = require('watchify');
var browserify = require('browserify');
var browserSync = require('browser-sync').create();
watchify.args.debug = true;
var bundler = watchify(browserify('./src/script.js', watchify.args));
bundler.transform(babelify.configure({
presets: ["es2015", "react"]
}));
bundler.on('update', bundle);
function bundle() {
gutil.log('Bundling...');
return bundler.bundle()
.on('error', function (err) {
gutil.log(err.message);
this.emit("end");
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream({once: true}));
}
gulp.task('bundle', function () {
return bundle();
});
gulp.task('default', ['bundle'], function () {
browserSync.init({
server: "./"
});
gulp.watch('index.html', function() {
browserSync.reload();
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment