突然,我的 gulpfile.js 对所有 jade 文件的监视语句停止工作。你知道为什么吗?
Jade 任务:
gulp.task('jade', function() {
gulp.src('app/*.jade')
.pipe(jade())
.on('error', function(err) {
console.log(err)
this.emit('end')
})
.pipe(minifyHTML())
.pipe(gulp.dest('dist/'))
.pipe(browserSync.stream())
})
我还使用 BrowserSync,因此我将所有监视语句放在 serve
任务中,如下所示:
gulp.task('serve', ['styles', 'html', 'jade', 'scripts'], function() {
browserSync.init({
server: './dist'
})
gulp.watch('app/css/**/*.sass', ['styles'])
gulp.watch('app/*.jade').on('change', function() {
gulp.run(['jade'])
browserSync.reload()
})
gulp.watch('app/src/*.js', ['scripts'])
})
此外,所有其他监视语句都有效,所以我真的不知道发生了什么。感谢您的帮助!
最佳答案
我会尝试两件事。
- 在
gulp.src('app/*.jade')
前面添加return
,以便管道知道它已完成(有关更多信息,请参阅 this question这个) - 将
jade
的gulp.watch
更改为gulp.watch('app/*.jade', ['jade']).on('更改', browserSync.reload())
。我觉得你的方式很奇怪。
我建议你从 Jade 升级到哈巴狗。
关于javascript - gulp.watch() 不适用于 Jade ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41782349/