Skip to content

Instantly share code, notes, and snippets.

@skywritergr
Created January 12, 2016 21:07
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 skywritergr/e802ba49ab5799b058a2 to your computer and use it in GitHub Desktop.
Save skywritergr/e802ba49ab5799b058a2 to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var source = require('vinyl-source-stream'); // Used to stream bundle for further handling
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var concat = require('gulp-concat');
gulp.task('browserify', function() {
var bundler = browserify({
entries: ['./public/js/render.jsx'], // Only need initial file, browserify finds the deps
transform: [reactify], // We want to convert JSX to normal javascript
debug: true, // Gives us sourcemapping
cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
});
var watcher = watchify(bundler);
return watcher
.on('update', function () { // When any files update
var updateStart = Date.now();
console.log('Updating!');
watcher.bundle() // Create new bundle that uses the cache for high performance
.pipe(source('bundle.js'))
// This is where you add uglifying etc.
.pipe(gulp.dest('./public/build/'));
console.log('Updated!', (Date.now() - updateStart) + 'ms');
})
.bundle() // Create the initial bundle when starting the task
.pipe(source('bundle.js'))
.pipe(gulp.dest('./public/build/'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment