【发布时间】:2014-02-15 16:17:46
【问题描述】:
我在我的 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 页面,无论我是否打开它,是否保存它,或其他任何东西:
[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 ...
有没有办法让它只实时重新加载保存的页面?这似乎是我唯一无法使用 gulp 进行工作的事情;不过,我喜欢它的运行速度比 grunt 快得多。
编辑:@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));
});
});
【问题讨论】:
-
-
我已经在上面发布了我的监视任务,因为整个文件似乎要发布的内容很多,但如果您愿意,我可以找到一种方法来发布更多内容!
-
你能把它发布在 jsfiddle 或 plunkr 上吗?让 livereload 与 PHP 一起工作对我来说将是一个巨大的帮助。
-
给你。如果您有任何问题,请告诉我。 codepen.io/thesublimeobject/pen/uzeJd
标签: javascript wordpress livereload gulp