[英]Problems with GULP Watch task. After compiling index.html from PUG, Gulp watch task don't refresh browser
我需要大量的任务。
从PUG编译index.html之后,Gulp监视任务不会刷新浏览器。
这是我的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();
});
但是什么都没有改变。 错误在哪里?
“浏览器同步”仅在标签“ body”有效。 当我测试这个Gulp任务时,我尝试了单个html标签,而没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.