简体   繁体   中英

Problems with GULP Watch task. After compiling index.html from PUG, Gulp watch task don't refresh browser

i need help with my gulp tasks.

After compiling index.html from PUG, Gulp watch task don't refresh browser.

This is my 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();
}); 

this is my 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'));
}); 

On the output I get compiled HTML code in folder './app/index.html'. Watch task must reload browser:

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

But nothing changes. Where is the mistake?

"browser-sync" only works there is tag "body". When I test this Gulp tasks, I experimented with single html tag, without .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM