Gulp does not come out with watchify, browser

I would like to configure gulp to be able to do two things: 1) use watchify to monitor updates in files and automatically reinstall using the browser for changes, and 2) make an advertising assembly once and exit.

# 1 seems to work fine, but it’s hard for me to work # 2. I type gulp build in the terminal, and everything in the kit is just fine, but gulp does not exit or does not exit; it just sits there, and I do not return to the command line.

What am I doing wrong? Here's the whole gulpfile file:

 'use strict'; var gulp = require('gulp'); var browserify = require('browserify'); var watchify = require('watchify'); var source = require('vinyl-source-stream'); var gutil = require('gulp-util'); var b = watchify(browserify({ cache: {}, packageCache: {}, entries: ['./app/app.js'], debug: true, transform: ['reactify'] })); b.on('log', gutil.log); var bundle = function() { return b.bundle() .pipe(source('bundle.js')) .pipe(gulp.dest('./dist')); }; gulp.task('watch', function() { b.on('update', bundle); }); gulp.task('build', function() { bundle(); }); gulp.task('default', ['watch', 'build']); 

And here is the output in my terminal:

 [11:14:42] Using gulpfile ~/Web Dev/event-calendar/gulpfile.js [11:14:42] Starting 'build'... [11:14:42] Finished 'build' after 4.28 ms [11:14:45] 1657755 bytes written (2.99 seconds) 

Gulp still works after the log at 11:14:45 and does not return back to the terminal.

+6
source share
1 answer

.bundle() should not be called in the watchify shell. All fixed:

 'use strict'; var gulp = require('gulp'); var browserify = require('browserify'); var watchify = require('watchify'); var source = require('vinyl-source-stream'); var gutil = require('gulp-util'); var b = function() { return browserify({ cache: {}, packageCache: {}, entries: ['./app/app.js'], debug: true, transform: ['reactify'] }); }; var w = watchify(b()); w.on('log', gutil.log); var bundle = function(pkg) { return pkg.bundle() .pipe(source('bundle.js')) .pipe(gulp.dest('./dist')); }; gulp.task('watch', function() { bundle(w); w.on('update', bundle.bind(null, w)); }); gulp.task('build', bundle.bind(null, b())); gulp.task('default', ['watch']); 
+6
source

All Articles