gulp watch doesn't watch

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

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

回答1:

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.



转载请标明出处:gulp watch doesn't watch
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!