吞咽手表不看 [英] gulp watch doesn't watch
问题描述
以下是我的gulpfile.js。其中有几个任务,并且所有工作都正常 - 但最后一项任务 watch
不会。
我已经尝试过所有可能的路径和文件组合,但仍然没有运气。我在这里阅读了很多答案,但无法解决我的问题。我试图运行gulp.watch,不需要大量的观看,尝试了几种不同的方法来设置任务,等等......
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var watch = require('gulp-watch');
gulp.task('application',function(){
return browserify('./ public / resources / jsx / application.js')
.transform(babelify, {stage:0})
.bundle()
.on('error',function(e){
console.log(e.message);
this.emit('end');
})
.pipe(source('appBundle.js'))
.pipe(gulp.dest('./ public / resources / jsx'));
});
gulp.task('watch',function(){
gulp.watch('./ public / resources / jsx / project / *。js',['application'])
});
有人可以提出一个解决方案吗?
编辑:
以下是控制台输出:
michael @ michael-桌面:/ opt / PhpstormProjects / app_april_2015 $ gulp watch
[23:05:03]使用gulpfile /opt/PhpstormProjects/app_april_2015/gulpfile.js
[23:05:03]开始观看。 ..
[23:05:03] 13 ms后完成'watch'
您应该返回
手表:
gulp.task('watch',function(){
return gulp.watch('./ public / resources / jsx / project / *。js',['application'])
}) ;
watch
是 async
方法,所以Gulp可以知道发生的事情的唯一方法就是如果你返回一个 promise
,该手表就是这样。
编辑
正如@JMM所述, watch
不会返回Promise。它返回一个 EventEmitter 。
Following is my gulpfile.js. There are a couple of more tasks in it and all are working fine - but the last task, watch
doesn't.
I've tried every possible combination of paths and files and what so ever, but still I don't have luck. I've read many answers on this here, but couldn't solve my problem. I tried to run gulp.watch with and without requiring gulp-watch, tried several different approaches on how to set up the task and so on and so on...
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var watch = require('gulp-watch');
gulp.task('application', function() {
return browserify('./public/resources/jsx/application.js')
.transform(babelify, { stage: 0 })
.bundle()
.on('error', function(e){
console.log(e.message);
this.emit('end');
})
.pipe(source('appBundle.js'))
.pipe(gulp.dest('./public/resources/jsx'));
});
gulp.task('watch', function() {
gulp.watch('./public/resources/jsx/project/*.js',['application'])
});
Can someone suggest a solution?
EDIT:
Here's the console output:
michael@michael-desktop:/opt/PhpstormProjects/app_april_2015$ gulp watch
[23:05:03] Using gulpfile /opt/PhpstormProjects/app_april_2015/gulpfile.js
[23:05:03] Starting 'watch'...
[23:05:03] Finished 'watch' after 13 ms
You should return
watch:
gulp.task('watch', function() {
return gulp.watch('./public/resources/jsx/project/*.js',['application'])
});
watch
is an async
method, so the only way Gulp can know that something is happening is if you return a promise
, which watch does.
Edit
As @JMM stated, watch
doesn't return a Promise. It returns an EventEmitter.
这篇关于吞咽手表不看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!