2014-04-21 35 views
1

我有一個基本的gulp.js設置在我的wordpress環境中運行。除了我重新加載更改後的.php文件的方式外,一切都可以運行。當gulp完成運行任務時,似乎要加載任務兩次,這意味着它將開始 - 完成任務,然後再次重新運行任務。我一直在觀看的文件位於根目錄以及庫目錄中。另外,有沒有辦法讓大家只查找更改過的文件。我有這樣設置:Gulp Refresh WordPress的PHP文件

// 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 … 

回答

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'); 
}); 

如果這個片段不應該工作,或節省時間保持高於一,嘗試編輯這一個:

gulp.task('php', function() { 
    watch({ 
    glob:['.php','library/.php'] 
    }) ... 

最好的問候。

注意: 完整代碼片段中的前兩行僅用於jshint,因此我可以證明代碼,但如果沒有本地php庫,則無法執行代碼。