ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-10-29 22:37:56  阅读:272  来源: 互联网

标签:livereload gulp wordpress javascript


我在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似乎有更多的功能.但是,两者都将无法检测到新文件.

标签:livereload,gulp,wordpress,javascript
来源: https://codeday.me/bug/20191029/1963404.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有