在hbs或css文件中更新后,Gulp不会重新加载页面,browserSync怎么了
这是gulpfile.js中的设置
"use strict";
var gulp = require('gulp'),
babel = require("gulp-babel"),
path = require('path'),
sass = require('gulp-sass'),
slang = require('gulp-slang'),
handlebars = require('handlebars'),
config = require('./gulp.config')(),
gulpHandlebars = require('gulp-handlebars-html')(handlebars),
regexRename = require('gulp-regex-rename'),
replace = require('gulp-replace'),
open = require('gulp-open'),
browserSync = require('browser-sync').create(),
baseURL = 'site-path/';
gulp.task('jstxt', function () {
return gulp.src(baseURL + 'js.txt')
.pipe(gulp.dest(baseURL));
});
gulp.task('csstxt', function () {
return gulp.src(baseURL + 'css.txt')
.pipe(gulp.dest(baseURL));
});
gulp.task('sass', function () {
return gulp.src(baseURL + 'style.scss')
.pipe(sass())
.pipe(gulp.dest(baseURL))
.pipe(browserSync.stream());
});
function reload(done) {
browserSync.reload();
done();
}
gulp.task('watch', function () {
gulp.watch(baseURL + "scss/*.scss", ['sass']);
gulp.watch(baseURL + 'js/*.js')
.on('change', function (js) {
if (js.path.length !== 0) {
return gulp.src(js.path);
} else {
return;
}
});
gulp.watch(baseURL + 'js.txt',['jstxt']);
gulp.watch(baseURL + 'css.txt',['csstxt']);
});
gulp.task('default', ['watch'], gulp.parallel(reload));
/* Handlebar Setup for Frontend */
gulp.task('compileHtml', function () {
var templateData = {
multiply: function multiply(a, b) {
return +a * +b;
}
},
options = {
partialsDirectory: [config.templatePartialPath]
};
return gulp.src(config.templatePath + "*.page.hbs")
.pipe(gulpHandlebars(templateData, options))
.pipe(regexRename(/\.page\.hbs$/, ".html"))
.pipe(replace(/\uFEFF/ig, "")) //cut out zero width nbsp characters the compiler adds in
.pipe(gulp.dest(config.templateOutputPath))
.pipe(browserSync.stream());
});
gulp.task('compileHtml:watch', function () {
return gulp.watch(config.templates, ['compileHtml'], gulp.parallel(reload));
});
// Open one file with default application
gulp.task('open', function () {
gulp.src('templates/dist/index.html')
.pipe(open());
});