如何使用 Vagrant VM 通过共享文件夹启用热重载? [英] How to enable hot reloading via shared folders with Vagrant VM?

查看:58
本文介绍了如何使用 Vagrant VM 通过共享文件夹启用热重载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的 react/redux 应用程序,它使用热重载(即,当我保存对源代码的更改时,它会通过 webpack 在浏览器中相应地更新我的应用程序的内容,保留我的应用程序的状态).这适用于 myhost 机器.

I have a very basic react/redux app utilizing hot reloading (i.e. when I save a change to my source code, it updates the contents of my app accordingly in browser, preserving the state of my app) via webpack. This works on myhost machine.

但是,如果我使用基于 vagrant 的工作流和同步文件夹(以便我可以使用我喜欢的非终端文本编辑器),并且我对我的主机上的源代码进行更改并保存,那么热重载是未触发.但是,如果我在来宾计算机上进行/保存更改(为了简单起见,仅使用 nano),热重载确实会触发.

However, if I use a vagrant-based workflow with synced folders (so that I can use my preferred non-terminal text editor) and I make and save a change to my source code on my host machine, the hot reloading is not triggered. However, if I make/save the change on the guest machine (just using nano for simplicity), the hot reloading does trigger.

澄清一下,从主机保存的更改会反映在来宾计算机的文件中,但不会触发热重载.如果我将 helloworld 更改为 Hello, World!在我的主机上,来宾计算机的该文件副本也会说 Hello, World!,但在我也在来宾计算机上保存该更改之前,不会触发热重载.

To clarify, the saved change from the host machine is reflected in the file in the guest machine, but it doesn't trigger hot reloading. If I change helloworld to Hello, World! on my host machine, the guest machine's copy of that file will also say Hello, World!, but until I also save that change on the guest machine, hot reloading will not trigger.

推荐答案

这个问题可能是由 Virtualbox 自己的共享文件夹文件系统引起的.

This issue could be caused by Virtualbox's own file system for shared folder.

根据https://github.com/webpack/webpack-dev-server/issues/155,你可以试试这个:

According to https://github.com/webpack/webpack-dev-server/issues/155, you could probably try this:

webpack-dev-server --watch-poll

此外,我相信使用 rsync 将始终有效(但这会稍微改变您的工作流程):

Additionally, I believe using rsync will always work (but this will slightly change your workflow):

Webpack 开发服务器重新加载在虚拟机上不起作用

这篇关于如何使用 Vagrant VM 通过共享文件夹启用热重载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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