Browsersync没有设置正确的本地URL

时间:2015-02-13 13:26:35

标签: wordpress browser-sync

我正在使用与MAMP PRO相关联的入门主题Roots with Gulp处理Wordpress项目。我遇到了“观看”的问题。来自gulpfile.js的任务。 以下是任务的代码:

gulp.task('watch', function() {
  browserSync({
    proxy: "mywebsite:8888",
    port: 8888,
    open: "internal"
  });
  gulp.watch([path.source + 'styles/**/*'], ['styles']);
  gulp.watch([path.source + 'scripts/**/*'], ['jshint', 'scripts']);
  gulp.watch(['bower.json'], ['wiredep']);
  gulp.watch('**/*.php', function() {
    browserSync.reload();
  });
});

这是推出' gulp手表后的终端输出。命令:

gulp watch
[12:46:32] Using gulpfile ~/Dropbox/_sites/mywebsite/wp-content/themes/mywebsitetheme/gulpfile.js
[12:46:32] Starting 'watch'...
[12:46:37] Finished 'watch' after 4.26 s
[BS] Proxying: http://mywebsite:8888
[BS] Now you can access your site through the following addresses:
[BS] Local URL: http://localhost:8888
[BS] External URL: http://192.168.22.168:8888

因此,浏览器同步使用我的默认浏览器打开了网址http://localhost:8888

基本上,我现在需要的是,生成的网址(由浏览器打开)为http://mywebsite:8888

1 个答案:

答案 0 :(得分:2)

感谢bower社区成员(github issue)解决了问题 我只需要删除任何配置选项,并在结束标记之前添加下面的代码段:

<script type='text/javascript' id="__bs_script__">//<![CDATA[
    document.write("<script async src='//HOST:PORT/browser-sync/browser-sync-client.2.1.0.js'><\/script>".replace(/HOST/g, location.hostname).replace(/PORT/g, location.port));
//]]></script>