简体   繁体   English

Gulp:观看HTML文件,执行一些任务,然后执行browserSync.reload

[英]Gulp: watch HTML files, do some task, then browserSync.reload

Our HTML files are 'assembled' from a few template/partial HTML files. 我们的HTML文件是从一些模板/部分HTML文件中“组合”而成的。 Now I want Gulp to be able to do these tasks sequentially : 现在,我希望Gulp能够依次执行以下任务:

  1. Watch 'template' HTML files 观看“模板” HTML文件
  2. If there is any update, run the tasks pages 如果有任何更新,请运行任务pages
  3. Then, refresh the webpage. 然后,刷新网页。

I read through this tutorial: https://www.browsersync.io/docs/gulp/ . 我通读了本教程: https : //www.browsersync.io/docs/gulp/ But it simply watches the HTML files and reload. 但是它只是监视HTML文件并重新加载。 I tried this: 我尝试了这个:

gulp.watch([
    path.join(dpw.src.commonLayouts, 'layout.html'),
    dpw.src.commonPages + "/**/*.html",
    dpw.src.sitePages + "/**/*.html"
], ['pages']).on("change", browserSync.reload);

The web page will be reloaded automatically. 该网页将自动重新加载。 And the task pages is run. 任务pages运行。

However, the refreshed page is always one version behind. 但是,刷新的页面始终落后一个版本。 It means, if I change some text from "12" to be "123", the page is refreshed but the text is "12". 这意味着,如果我将某些文本从“ 12”更改为“ 123”,则页面会刷新,但文本为“ 12”。 Then I change to "1234", the page is refreshed to be "123"... 然后我更改为“ 1234”,页面刷新为“ 123” ...

I am using Gulp 3.9.0 and browser-sync 2.11.1. 我正在使用Gulp 3.9.0和browser-sync 2.11.1。

Please help. 请帮忙。 Thanks. 谢谢。

Thanks to @MatthewRath, I implemented it using runSequence : 感谢@MatthewRath,我使用runSequence实现了它:

gulp.task('pages-watch', function () {
    runSequence('pages', browserSync.reload);
});

gulp.watch([
    path.join(dpw.src.commonLayouts, 'layout.html'),
    dpw.src.commonPages + "/**/*.html",
    dpw.src.sitePages + "/**/*.html"
], ['pages-watch']);

But it introduces a new task, which is a bit tedious. 但是它引入了一个新任务,这有​​点乏味。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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