我在wordpress环境中运行了一个基本的gulp.js设置。除了重新加载我更改的.php文件的方式之外,一切都按照我想要的方式工作。当gulp完成运行任务时,它似乎正在加载任务两次,这意味着它将开始完成任务然后再次重新运行任务。我吞咽的文件位于根目录和库目录中。还有,有一种方法可以让gulp只查找已更改的文件。我把它设置成这样:
// PHP TASK
gulp.task(‘php’, function () {
watch({glob:['.php','library/.php']})
.pipe(plugins.livereload(server))
.pipe(plugins.notify({ message: ‘PHP task complete’ }));
});
// Watch
gulp.task(‘watch’, function() {
// Listen on port 35729
server.listen(35729, function (err) {
if (err) {
return console.log(err)
};
// Watch php files
gulp.watch(['php']);
});
});
// Default task
gulp.task(‘default’, ['php', 'watch']);
====================================
以下是单次保存的结果。
[gulp] index.php was reloaded.
… Reload /Users/jfearing/Sites/zurb/wp-content/themes/JointsWP-CSS-master/index.php …
… Reload /Users/jfearing/Sites/zurb/wp-content/themes/JointsWP-CSS-master/index.php …
… Reload /Users/jfearing/Sites/zurb/wp-content/themes/JointsWP-CSS-master/index.php …
… Reload /Users/jfearing/Sites/zurb/wp-content/themes/JointsWP-CSS-master/index.php …
[gulp] index.php was reloaded.
… Reload /Users/jfearing/Sites/zurb/wp-content/themes/JointsWP-CSS-master/index.php …
… Reload /Users/jfearing/Sites/zurb/wp-content/themes/JointsWP-CSS-master/index.php …
… Reload /Users/jfearing/Sites/zurb/wp-content/themes/JointsWP-CSS-master/index.php …
答案 0 :(得分:1)
而不是:
你可以试试这个:// Default task gulp.task(‘default’, ['php', 'watch']);
// Default task
gulp.task('default', ['php'], function() {
gulp.start('watch');
});
但目前我无法测试它。
完整摘录:
'use strict';
/* global gulp, watch, plugins, server, console */
// PHP TASK
gulp.task('php', function () {
watch({
glob:['.php','library/.php']
}).pipe(plugins.livereload(server))
.pipe(plugins.notify({ message: 'PHP task complete' }));
});
// Watch
gulp.task('watch', function() {
// Listen on port 35729
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
// Watch php files
gulp.watch(['php']);
});
});
// Default task
gulp.task('default', ['php'], function() {
gulp.start('watch');
});
如果此代码段无效或保存时间高于1,请尝试编辑此代码:
gulp.task('php', function () {
watch({
glob:['.php','library/.php']
}) ...
最好的问候。
注意: 完整代码片段中的前两行仅用于jshint,因此我可以证明代码,而如果没有本地定位的php-library则无法执行代码。