Browser Sync + Gulp + Jade,为什么要分开Jade watch任务?

时间:2015-08-05 16:50:01

标签: javascript gulp pug browser-sync

我正在查看这个browser sync recipe这是一个gulpfile配置,适用于jade,sass和浏览器同步,我不关心sass所以为了简化我修改了一点代码:

var gulp        = require('gulp');
var browserSync = require('browser-sync');
var jade        = require('gulp-jade');
var reload      = browserSync.reload;

/**
 * Compile jade files into HTML
 */
gulp.task('templates', function() {
    return gulp.src('./app/*.jade')
        .pipe(jade())
        .pipe(gulp.dest('./dist/'));
});

/**
 * Important!!
 * Separate task for the reaction to `.jade` files
 */
gulp.task('jade-watch', ['templates'], reload);


/**
 * Serve and watch the jade files for changes
 */
gulp.task('default', ['templates'], function () {
    browserSync({server: './dist'});
    gulp.watch('./app/*.jade', ['jade-watch']);
});

我不明白的是这条评论:

/**
 * Important!!
 * Separate task for the reaction to `.jade` files
 */

为什么这很重要?为什么不这样做?

/**
 * Compile jade files into HTML
 */
gulp.task('templates', function() {
    return gulp.src('./app/*.jade')
        .pipe(jade())
        .pipe(gulp.dest('./dist/'))
        .pipe(reload({stream: true}));
});

/**
 * Serve and watch the jade files for changes
 */
gulp.task('default', ['templates'], function () {
    browserSync({server: './dist'});
    gulp.watch('./app/*.jade', ['templates']);
});

1 个答案:

答案 0 :(得分:0)

你现在可能已经想到了这一点;但是如果有其他人想到同样的事情(就像我做的那样):通过设置'模板'作为jade-watch' jade-watch'确保在触发重新加载之前已完成。

相关问题