【问题标题】:Problems with GULP Watch task. After compiling index.html from PUG, Gulp watch task don't refresh browserGULP Watch 任务的问题。从 PUG 编译 index.html 后,Gulp 监视任务不刷新浏览器
【发布时间】:2017-06-05 18:33:12
【问题描述】:

我的 gulp 任务需要帮助。

从 PUG 编译 index.html 后,Gulp watch 任务不刷新浏览器。

这是我的 watch.js

var gulp = require('gulp'),
    watch = require('gulp-watch'),
    browserSync = require('browser-sync').create();


gulp.task('watch', function(){
    browserSync.init({
        notify: false, 
        server: {
            baseDir: "app"
        } 
    });

    watch('./app/index.html', function(){
        browserSync.reload();
    });

    watch('./app/assets/pug/*.pug', function(){
        gulp.start('htmlRefresh');
    });
});

gulp.task('htmlRefresh', ['pug'] ,function(){
    browserSync.reload();
}); 

这是我的 pug.js

var gulp = require('gulp'),
    pug =  require('gulp-pug'),
    notify = require('gulp-notify');

gulp.task('pug',function(){
   return gulp.src('./app/assets/pug/*.pug')
   .pipe(pug({ pretty: true }))
   .on('error', notify.onError(function (error) {
    return {
        title: 'Pug',
        message: error.message
    } 
}))
   .pipe(gulp.dest('./app'));
}); 

在输出中,我在文件夹“./app/index.html”中获得编译的 HTML 代码。观看任务必须重新加载浏览器:

watch('./app/index.html', function(){
    browserSync.reload();
});

但没有任何改变。 哪里错了?

【问题讨论】:

    标签: javascript gulp pug gulp-watch gulp-browser-sync


    【解决方案1】:

    "browser-sync" 仅适用于标签 "body"。当我测试这个 Gulp 任务时,我尝试了单个 html 标签,没有。

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      • 2015-03-11
      • 2015-07-14
      相关资源
      最近更新 更多