Skip to content

Instantly share code, notes, and snippets.

@apfelbox
Last active February 21, 2017 15:26
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apfelbox/b2d5ee9fe32e5b42adb2 to your computer and use it in GitHub Desktop.
Save apfelbox/b2d5ee9fe32e5b42adb2 to your computer and use it in GitHub Desktop.
(gulp + browserify) - gulp-browserify
var watch = require("gulp-watch");
var plumber = require("gulp-plumber");
var tap = require("gulp-tap");
var browserify = require("browserify");
var gulpif = require("gulp-if");
var streamify = require("gulp-streamify");
var gutil = require('gulp-util');
var isDebug = false;
watch(
{
glob: "src/js/**/*.js"
},
function ()
{
// my browserify entry points are the files directly in the js directory, included files are in subfolders
return gulp.src("src/js/*.js")
.pipe(plumber())
.pipe(tap(
function (file)
{
var d = require('domain').create();
d.on("error",
function (err) {
gutil.log(gutil.colors.red("Browserify compile error:"), err.message, "\n\t", gutil.colors.cyan("in file"), file.path);
gutil.beep();
}
);
d.run(function () {
file.contents = browserify({
entries: [file.path],
debug: isDebug
}).bundle();
});
}
))
.pipe(gulpif(!isDebug, streamify(uglify({
compress: true
}))))
.pipe(gulp.dest("out/");
}
);
@randseay
Copy link

@dougmacklin I was running into this same issue, but found a way around it. Whilst handling the error, be sure to end the task. This way gulp can continue watching your files once again.

.on('error', function(err) {
    gutil.log(
        gutil.colors.red('Browserify compile error:'),
        err.message
    );
    gutil.beep();
    this.emit('end'); // Ends the task
});

@cipiripper
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment