简体   繁体   English

Gulp不会以watchify,browserify退出

[英]Gulp doesn't exit with watchify, browserify

I would like to set up gulp to be able to do two things: 1) use watchify to monitor updates in files and automatically rebuild using browserify on changes, and 2) do an ad-hoc build once and exit. 我想设置gulp能够做两件事:1)使用watchify来监控文件中的更新并使用browserify自动重建更改,以及2)进行一次ad-hoc构建并退出。

#1 seems to be working fine, but I'm having trouble getting #2 to work. #1似乎工作正常,但我无法让#2工作。 I type gulp build in the terminal and everything is bundled up just fine, but gulp doesn't exit or quit; 我在终端输入gulp build ,所有东西都捆绑得很好,但gulp不会退出或退出; it just sits there and I'm not brought back to the command line. 它只是坐在那里,我没有带回命令行。

What am I doing wrong? 我究竟做错了什么? Here's the entire gulpfile: 这是整个gulpfile:

'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's 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 is still running after the log at 11:14:45 and doesn't jump back out to the terminal. Gulp在11:14:45之后仍然在日志后运行,并且没有跳回到终端。

.bundle() shouldn't be called on the watchify wrapper. 不应在watchify包装器上调用.bundle() The following fixed everything: 以下修正了一切:

'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']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Browserify + Watchify + Tsify + Gulp的性能问题 - Performance issues with Browserify + Watchify + Tsify + Gulp 带有watchify / browserify的Gulp运行一次,然后停止观看 - Gulp with watchify/browserify runs once then stops watching Gulp with watchify / browserify运行两次然后停止观看 - Gulp with watchify/browserify runs twice then stops watching 当使用Watchify时,Browserify + Babelify Gulp任务不会终止 - Browserify + Babelify Gulp task is not terminating, when Watchify is used 使用gulp + browserify + watchify + coffeeify尝试重新传输javascript而不是coffeescript - Using gulp + browserify + watchify + coffeeify tries to retranspile javascript instead of coffeescript Browserify编译为完整的系统路径(使用watchify和gulp) - Browserify compiling to full system paths (using watchify & gulp) browserify watchify产生错误 - browserify watchify produces errors gulp在运行任务后不会退出 - gulp doesn't exit after running tasks 如何在多个条目文件上使用Browserify + Watchify + Tsify + Gulp并快速获取多个输出文件 - How to use Browserify + Watchify + Tsify + Gulp on multiple entry files and get multiple output files quickly 使用gulp + browserify + reactify,当遇到ReactifyError时无法发出退出 - use gulp+browserify+reactify, can't emit exit when got a ReactifyError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM