【问题标题】:Browser Sync + Gulp + Jade, Why separate the Jade watch task?Browser Sync + Gulp + Jade,为什么要分离 Jade watch 任务?
【发布时间】:2015-08-05 16:50:01
【问题描述】:

我在看这个browser sync recipe,它是一个 gulpfile 配置,适用于 jam、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']);
});

【问题讨论】:

    标签: javascript gulp pug browser-sync


    【解决方案1】:

    您现在可能已经想通了;但万一其他人想知道同样的事情(和我一样):通过将“模板”任务设置为“玉手表”的依赖项,您可以确保它在触发重新加载之前已经完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 2014-08-07
      • 1970-01-01
      • 2012-12-23
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多