2015-06-04 41 views
0

我正在拼凑一个大文件,我想知道是否可以将gulp-notify(或其他解决方案)与watch任务结合起来,以便在watch任务开始运行时弹出一条消息。我无法从我的搜索中找到任何关于如何执行此操作的信息。它甚至有可能吗?是否有可能在watch任务中运行gulp-notify?

这里是我的手表任务:

// Watch our files for changes 
gulp.task('watch', function() { 

    // -- I wanna run a notify message here saying 'Watching for changes...' -- // 

    gulp.watch('assets/styles/**/*.scss', ['styles']); 
    gulp.watch('assets/scripts/**/*.js', ['scripts']); 
    gulp.watch('assets/images/**/*', ['images']); 
}); 

回答

-2

你就不能使用

gulp.task('watch', function() { 

    console.log('Watching for changes...'); 

    gulp.watch('assets/styles/**/*.scss', ['styles']); 
    gulp.watch('assets/scripts/**/*.js', ['scripts']); 
    gulp.watch('assets/images/**/*', ['images']); 
}); 
+0

那倒只是将它打印到控制台上,因为我不想在那里查看它何时开始,所以它没有任何用处。 – Chrillewoodz

0

我设法做它吞掉,通知和节点通知。 在完成任务之后,管道通知程序和回调中使用node-notifier来显示弹出窗口。

var notify = require('gulp-notify'); 
var nodeNotifier = require('node-notifier'); 

gulp().src(options.src) 
.pipe(gulp.dest(options.dest)) 
.pipe(notify(function() { 
    nodeNotifier.notify({ 
     'title': 'App', 
     'message': 'Build' 
    }); 
})); 
1

这应做到:

gulp.task('watch', function() { 
    notify("Watching for changes...").write(''); 

    gulp.watch('assets/styles/**/*.scss', ['styles']); 
    gulp.watch('assets/scripts/**/*.js', ['scripts']); 
    gulp.watch('assets/images/**/*', ['images']); 
}); 

此外,如果你的意思是,每次有一个通知文件更改,你可以做这样的事情:

gulp.task('watch', function() { 
    //... 

    gulp.watch([ 
     './src/**/*.html', 
     './src/**/*.php', 
    ]).on('change', function() { 
     browserSync.reload(); 
     notify("File changed: browser synced").write(''); 
    }); 
}); 
相关问题