【问题标题】:Gulp Refresh Wordpress PHP filesGulp 刷新 Wordpress PHP 文件
【发布时间】:2014-04-21 21:29:59
【问题描述】:

我在我的 wordpress 环境中运行了一个基本的 gulp.js 设置。除了我重新加载更改的 .php 文件的方式之外,一切都按我的意愿进行。当 gulp 完成运行任务时,它似乎正在加载任务两次,这意味着它将开始 - 完成任务然后再次重新运行任务。我让 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 …

【问题讨论】:

    标签: php wordpress gulp


    【解决方案1】:

    而不是这个:

    // Default task
    gulp.task(‘default’, ['php', 'watch']);
    

    你可以试试这个:

    // Default task
    gulp.task('default', ['php'], function() {
      gulp.start('watch');
    });
    

    但我目前无法对其进行测试。

    完整的sn-p:

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

    如果这个 sn-p 不起作用,或者保存时间一直高于 1,请尝试编辑这个:

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

    最好的问候。

    注意: 完整 sn-p 中的前两行仅用于 jshint,因此我可以证明代码,而如果没有本地的 php-library,我将无法执行它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多