javascript-Gulp.js:重新载入更改过的php / html页面

我在wordpress环境中运行了基本的gulp.js设置.除了重新加载已更改的.php文件的方式之外,一切都按我希望的方式运行.我有这样设置:

gulp.task('php', function(){
    gulp.src('../*.php').pipe(livereload(server));
});

    gulp.task('watch', function() {
        server.listen(35729, function (err) {
            if (err) {
                return console.log(err)
            };
            gulp.watch('styl/src/*.scss', ['styl']);
            gulp.watch('js/src/*.js', ['js']);
            gulp.watch('../*.php', ['php']);
        });
    });

我基本上只是在每次保存任何php文件时让它重新加载页面,但是每当我保存一个php文件时,它都会自动刷新每个php页面,无论我是否打开它,是否保存了它或其他任何东西:

[gulp] footer.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/footer.php ...
[gulp] front-page.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/front-page.php ...
[gulp] functions.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/functions.php ...
[gulp] header.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/header.php ...
[gulp] index.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/index.php ...
[gulp] social-media.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/social-media.php ...
[gulp] template-contact.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/template-contact.php ...
[gulp] template-interior.php was reloaded.
... Reload /Users/KBD/sites/vi/cnt/themes/vi/template-interior.php ...

有什么方法可以让我只重新保存已保存的页面吗?这似乎是我无法完全按照我的意愿工作的唯一方法.我爱它比奔跑快多少.

编辑:@SirTophamHatt

gulp.task('watch', function() {
    server.listen(35729, function (err) {
        if (err) {
            return console.log(err)
        };
        gulp.watch('styl/src/*.scss', ['styl']);
        gulp.watch('js/src/*.js', ['js']);
        gulp.watch('js/src/*.coffee', ['coffee']);
        gulp.src('../*.php').pipe(watch()).pipe(livereload(server));

    });
});

解决方法:

请改用gulp-watch plugin.查看单个文件,然后仅将其传递给结果,会更好.另外,如果您使用watch({glob:[‘files’]}).pipe(…)而不是gulp.src([‘files’]).pipe(watch( )).管(…).

另一种选择是使用gulp-newergulp-changed,它们都使用时间戳来确定文件是否已更改.我也没有个人使用过,但是gulp-newer似乎有更多的功能.但是,两者都将无法检测到新文件.

上一篇:JavaScript-什么是gulp任务异步运行提示?


下一篇:javascript-使用webpack和lodash捆绑依赖库