【发布时间】:2016-10-29 08:11:56
【问题描述】:
我正在开发一个网站构建工具 (https://github.com/bmargogne/website-builder.git)。 BrowserSync 在根 index.html 上可以完美运行,但它不会在其他任何地方重新加载...
这是我的(简化)方式......假设我有:
src/index.html
src/_header.html
src/page/index2.Html
一项任务构建 HTML 页面,包括 html 部分(它们的名称以“_”开头)
gulp.task('pagesHtml', () => {
const SRC = 'src/**/*.html';
const EXCLUDE = '!src/**/_*.html';
return gulp.src( [SRC, EXCLUDE], { ignoreInitial: false } )
pipe( fileinclude({ prefix: '@@', basepath: co.src }))
.pipe( gulp.dest( 'www/' ));
});
一项任务启动浏览器同步服务器
gulp.task('serveLocal', () => {
return browserSync.init({
server:{ baseDir : 'www' },
port: 3000,
open: true
});
});
调用一个任务来重新加载 browserSync(分开,因为它被我项目中的其他“观察者任务”调用)
gulp.task('liveReload', ()) => {
browserSync.reload();
});
还有一项任务查看所有 HTML(包括部分 HTML),应该重建整个页面,然后重新加载。
gulp.task('watch-pagesHtml', () => {
const SRC = 'src/**/*.html';
return watch( SRC, () => {
runSequence('pagesHtml', 'liveReload');
});
return;
});
我通过像这样启动 runSequence 开始这些任务:
gulp.task('default', () => {
runSequence('pagesHtml', 'watch-pagesHtml');
});
当我在 index 或 _header 工作时:完全没有问题!应用、构建更改并重新加载浏览器。
但是,当我在 pages/index2 上工作时,会应用并构建更改,但不会重新加载浏览器。 (虽然 F5 可以工作并显示应用的更改)
我做错了什么?
【问题讨论】:
标签: gulp browser-sync