Last active
February 21, 2017 15:26
-
-
Save apfelbox/b2d5ee9fe32e5b42adb2 to your computer and use it in GitHub Desktop.
(gulp + browserify) - gulp-browserify
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
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/"); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.