简体   繁体   中英

gulp watch doesn't watch

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM