browsersync gulp proxing与wordpress get_template_path不兼容

时间:2015-07-27 11:41:06

标签: gulp gulp-watch browser-sync

我有一个奇怪的问题。我使用浏览器同步和gulp为我的wp项目出现奇怪的事情。我用gulp服务任务:

gulp.task('serve', ['styles'], function() {
    browserSync.init(null, {
        proxy : localhost:8888/mywpsite,
        debugInfo: true,
        open: true
    });
});

和一些gulp替换wiredep任务为我的主题使其像wp:

gulp.task('wiredep', function() {
    var wiredep = require('wiredep').stream;
    gulp.src('**/*.php')
      .pipe(wiredep({
          directory: 'bower_components'
      }))
      .pipe(replace(/(<script src=")(bower_components\/)/g, '$1<?php echo get_template_directory_uri(); ?>/$2'))
      .pipe(gulp.dest(''));
});

这个结果在我的footer.php文件中的html标记如下:

<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/modernizr/modernizr.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/jquery/dist/jquery.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/fastclick/lib/fastclick.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/jquery.cookie/jquery.cookie.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/jquery-placeholder/jquery.placeholder.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/foundation/js/foundation.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/snap.svg/dist/snap.svg-min.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/fullpage.js/jquery.fullPage.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/bower_components/waypoints/lib/jquery.waypoints.js"></script>
<!-- endbower -->
<!-- endbuild -->

当我运行gulp服务时,我看到我的输出html文件是这样的:

<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/modernizr/modernizr.js"></script>
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/jquery/dist/jquery.js"></script>
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/fastclick/lib/fastclick.js"></script>
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/jquery.cookie/jquery.cookie.js"></script>
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/jquery-placeholder/jquery.placeholder.js"></script>
<script src="http://localhost:8888/mywpsite/wp-content/themes/konstrukt/bower_components/foundation/js/foundation.js"></script>
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/snap.svg/dist/snap.svg-min.js"></script>
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/fullpage.js/jquery.fullPage.js"></script>
<script src="//localhost:3000/mywpsite/wp-content/themes/konstrukt/bower_components/waypoints/lib/jquery.waypoints.js"></script>
<!-- endbower -->
<!-- endbuild -->

为什么基金会已经通过http://localhost:8888提出的任何想法? 我已经尝试了清除缓存,但没有运气。我也尝试改变bower_components的顺序,看起来第6个组件总是与其他组件不同。

1 个答案:

答案 0 :(得分:0)

这是一个浏览器同步问题,已经通过2.8.0版解决了。我已经更新,现在工作正常!