Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

javascript - 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...