浏览器同步+ Gulp +翡翠,为什么分开翡翠手表任务



我在看这个浏览器同步配方这是一个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']);
});

你现在可能已经明白了;但是如果其他人也想知道同样的事情(和我一样):通过将'templates'任务设置为'jade-watch'的依赖项,您可以确保它在触发重新加载之前完成。

最新更新