Reputation: 11
I have a basic gulp.js setup running in my wordpress environment. Everything works how I would like except for the way I am reloading my changed .php files. When gulp finishes running the task it seems to be loading the task twice meaning that it will start-finish the task then re-run the task again. The files I had gulp watching are located in the root directory as well as the library directory. Also, is there a way to have gulp only look for changed files. I have it set up like this:
// 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']);
====================================
Here is the result from a single save.
[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 …
Upvotes: 1
Views: 1297
Reputation: 273
Instead of this:
// Default task gulp.task(‘default’, ['php', 'watch']);
you could try this:
// Default task
gulp.task('default', ['php'], function() {
gulp.start('watch');
});
But I can't test it out, at the moment.
Full snippet:
'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');
});
If this snippet should not work, or the save times keeps higher than one, try to edit this one:
gulp.task('php', function () {
watch({
glob:['.php','library/.php']
}) ...
Best regards.
Note: The first two lines in the full snippet are just for jshint, so I can proof the code, while I can't execute it without a local located php-library.
Upvotes: 1