Created
January 12, 2016 21:07
-
-
Save skywritergr/e802ba49ab5799b058a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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