BrowserSync +带有Vagrant的Gulp不会让人耳目一新 [英] BrowserSync + Gulp with Vagrant not refreshing

查看:243
本文介绍了BrowserSync +带有Vagrant的Gulp不会让人耳目一新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用BrowserSync和Gulp在特定种类的文件发生更改时使用本地计算机重新加载站点。我在 gulpfile 中有以下代码片段:

  gulp.task ('browser-sync',function(){
browsersync.init({
proxy:mySite:8080,
files:[./*.html,dev / * .css]
});
});

在更改(并保存)上述任何类型的文件时,我会得到如下输出我的终端:

  [BS]服务文件来自:./ 
[BS]正在观看文件...
[BS]文件已更改:index.html
[BS]文件已更改:dev \styles.css

一直以来,网站按预期重新加载,但其内容并未反映所做的更改。我无法弄清楚我在这里做错了什么。任何暗示赞赏!






更新

我忘了提及我的主机运行的是Windows 10,而我的客机正在运行Ubuntu 14.04.4 LTS。 VM提供程序是VirtualBox。



最初,我使用默认的 config.vm.synced_folder 方法。我在 vagrantfile

  config.vm.synced_folder / Path / To / My / Host / Website / Folder /,/ usr / nginx / html / mywebsite /

我从此尝试过使用NFS,并使用以下配置:

  config.vm.synced_folder/ Path / To / My / Host / Website / Folder /,/ usr / nginx / html / mywebsite /,
:type => :nfs,
:mount_options => ['nolock,vers = 3,udp,noatime,actimeo = 1']

运行Windows,我安装了插件 vagrant-winnfsd ,它增加了对NFS的支持。但现在vagrant暂停,当它试图挂载NFS共享文件夹。



另外,因为我在 vagrant up 您的主机(5.0.16)和guest(4.3.36)上的GuestAdditions版本不匹配,我安装了插件 vagrant-vbgues ,以保持VirtualBox Guest Additions是最新的。也无济于事。 Vagrant在尝试挂载NFS共享文件夹时仍处于冻结状态。

解决方案

偶然发现问题与VirtualBox有关,如此处所述。因为我在VirtualBox的虚拟机上运行Nginx,所以我的问题的解决方案是注释 nginx.conf 中的 sendfile code>,或者直接将其设置为:

  sendfile off; 

同样的问题被报告这里这里。除了流浪汉文档,其中声明有与 sendfile 有关的VirtualBox错误,这可能导致损坏或未更新的文件。


I'm using BrowserSync with Gulp to live reload a site in a local machine when specific kinds of files are changed. I've the following snippet in my gulpfile:

gulp.task('browser-sync', function() {
    browsersync.init({
        proxy: "mySite:8080",
        files: ["./*.html", "dev/*.css"]
    });
});

When changing (and saving) any of the above kinds of files, I get an output like this in my terminal:

[BS] Serving files from: ./
[BS] Watching files...
[BS] File changed: index.html
[BS] File changed: dev\styles.css

All the while, the site reloads as expected, but its content does not reflect the changes that were made. I can't figure out what am I doing wrong here. Any hint appreciated!


UPDATE

I forgot to mention that my host machine is running Windows 10 and my guest machine is running Ubuntu 14.04.4 LTS. The VM provider is VirtualBox.

Initially, I was using the default config.vm.synced_folder method. I had this on my vagrantfile:

config.vm.synced_folder "/Path/To/My/Host/Website/Folder/", "/usr/nginx/html/mywebsite/"

I've since tried using NFS, with the following configuration:

config.vm.synced_folder "/Path/To/My/Host/Website/Folder/", "/usr/nginx/html/mywebsite/", 
:type => :nfs, 
:mount_options => ['nolock,vers=3,udp,noatime,actimeo=1']

Since my host is running Windows, I installed the plugin vagrant-winnfsd, which adds support for NFS. But now vagrant halts when it tries to mount the NFS shared folder.

In addition, since I was getting the following error on vagrant up: GuestAdditions versions on your host (5.0.16) and guest (4.3.36) do not match, I installed the plugin vagrant-vbgues, in order to keep VirtualBox Guest Additions up to date. At no avail either. Vagrant is still freezing when it tries to mount the NFS shared folder.

解决方案

It so happens that the problem was related with VirtualBox, as explained here. Since I'm running Nginx on a virtual machine in VirtualBox, the solution to my problem was to comment out the sendfile directive in nginx.conf, or simply set it off, like this:

sendfile off;

The same issue is reported here, and here. As well as in the Vagrant docs, which state that "There is a VirtualBox bug related to sendfile which can result in corrupted or non-updating files."

这篇关于BrowserSync +带有Vagrant的Gulp不会让人耳目一新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆