BrowserSync + Gulp 与 Vagrant 不刷新
BrowserSync + Gulp with Vagrant not refreshing
我将 BrowserSync 与 Gulp 结合使用,以便在更改特定类型的文件时在本地计算机中实时重新加载站点。我的 gulpfile
:
中有以下片段
gulp.task('browser-sync', function() {
browsersync.init({
proxy: "mySite:8080",
files: ["./*.html", "dev/*.css"]
});
});
当更改(和保存)上述任何类型的文件时,我在终端中得到如下输出:
[BS] Serving files from: ./
[BS] Watching files...
[BS] File changed: index.html
[BS] File changed: 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
上收到以下错误:GuestAdditions versions on your host (5.0.16) and guest (4.3.36) do not match
,我安装了插件 vagrant-vbgues,以便使 VirtualBox Guest Additions 保持最新。也无济于事。 Vagrant 在尝试装载 NFS 共享文件夹时仍然冻结。
标题和标签表明您正在使用 Vagrant,尽管您的问题中并未提及。
确保您的更改正在同步到 VM。查看 vagrant documentation 到 select 适合您情况的同步文件夹类型。他们的基本例子如下:
Vagrant.configure("2") do |config|
# other config here
config.vm.synced_folder "src/", "/srv/website"
end
您可以 vagrant ssh
并手动检查文件以确保它们匹配,并确保同步的文件夹按预期工作。
更新
根据新的信息和评论,我建议使用 rsync
作为共享文件夹的方法。
config.vm.synced_folder "Host/Path/", "/Guest/Path", type: "rsync",
rsync__exclude: [ '.git', 'logs'],
rsync__args: ["--verbose"],
rsync__chown: false
如果 Windows 在混合中,我从来没有找到让 NFS 发挥良好(和表现良好)的方法。
碰巧问题与 VirtualBox 有关,如 here 所述。由于我在 VirtualBox 中的虚拟机上使用 运行 Nginx,我的问题的解决方案是在 nginx.conf
中注释掉 sendfile
指令,或者简单地设置它,如下所示:
sendfile off;
报告了同样的问题 here, and here. As well as in the Vagrant docs,其中指出 "There is a VirtualBox bug related to sendfile
which can result in corrupted or non-updating files."
我将 BrowserSync 与 Gulp 结合使用,以便在更改特定类型的文件时在本地计算机中实时重新加载站点。我的 gulpfile
:
gulp.task('browser-sync', function() {
browsersync.init({
proxy: "mySite:8080",
files: ["./*.html", "dev/*.css"]
});
});
当更改(和保存)上述任何类型的文件时,我在终端中得到如下输出:
[BS] Serving files from: ./
[BS] Watching files...
[BS] File changed: index.html
[BS] File changed: 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
上收到以下错误:GuestAdditions versions on your host (5.0.16) and guest (4.3.36) do not match
,我安装了插件 vagrant-vbgues,以便使 VirtualBox Guest Additions 保持最新。也无济于事。 Vagrant 在尝试装载 NFS 共享文件夹时仍然冻结。
标题和标签表明您正在使用 Vagrant,尽管您的问题中并未提及。
确保您的更改正在同步到 VM。查看 vagrant documentation 到 select 适合您情况的同步文件夹类型。他们的基本例子如下:
Vagrant.configure("2") do |config| # other config here config.vm.synced_folder "src/", "/srv/website" end
您可以 vagrant ssh
并手动检查文件以确保它们匹配,并确保同步的文件夹按预期工作。
更新
根据新的信息和评论,我建议使用 rsync
作为共享文件夹的方法。
config.vm.synced_folder "Host/Path/", "/Guest/Path", type: "rsync",
rsync__exclude: [ '.git', 'logs'],
rsync__args: ["--verbose"],
rsync__chown: false
如果 Windows 在混合中,我从来没有找到让 NFS 发挥良好(和表现良好)的方法。
碰巧问题与 VirtualBox 有关,如 here 所述。由于我在 VirtualBox 中的虚拟机上使用 运行 Nginx,我的问题的解决方案是在 nginx.conf
中注释掉 sendfile
指令,或者简单地设置它,如下所示:
sendfile off;
报告了同样的问题 here, and here. As well as in the Vagrant docs,其中指出 "There is a VirtualBox bug related to sendfile
which can result in corrupted or non-updating files."