Last active
August 29, 2015 14:05
-
-
Save L1fescape/0569816d325ddc75f4fa to your computer and use it in GitHub Desktop.
Seperate Gulp browserify and watchify tasks
This file contains hidden or 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
'use strict'; | |
var gulp = require('gulp'); | |
var browserify = require('browserify'); | |
var watchify = require('watchify'); | |
var source = require('vinyl-source-stream'); | |
var notify = require('gulp-notify'); | |
// Helper functions | |
function handleErrors(){ | |
var args = Array.prototype.slice.call(arguments); | |
// Send error to notification center with gulp-notify | |
notify.onError({ | |
title: "Compile Error", | |
message: "<%= error.message %>" | |
}).apply(this, args); | |
// Keep gulp from hanging on this task | |
this.emit('end'); | |
} | |
function bundle(args){ | |
var bundler; | |
if( args ){ | |
bundler = browserify('./app/javascripts/main.js', args); | |
} else { | |
bundler = browserify('./app/javascripts/main.js'); | |
} | |
bundler.bundle() | |
.on('error', handleErrors) | |
.pipe(source('app.js')) | |
.pipe(gulp.dest('./dist/')); | |
return bundler; | |
} | |
// Tasks | |
gulp.task('browserify', bundle); | |
gulp.task('watch', function() { | |
var bundler = watchify( bundle(watchify.args) ); | |
bundler.on('update', bundle); | |
return bundler; | |
}); | |
gulp.task('default', ['watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this still needs to be revised because of a memory leak due to constantly calling browserify. Should just be calling
.bundle()
instead ofbrowserify
each time.