调试 Docker 卷挂载停止更新时的 Vite 热重载问题

我在一个运行于 Docker Compose 中的小型 React 项目上遇到了一个令人沮丧的 Vite 问题。应用启动正常,测试通过,浏览器也能正常加载,但热重载在几分钟后就无法检测到文件更改了。起初看起来像是 Vite 的 bug,因为保存同一个文件两次,有时会触发重新构建,有时却毫无反应。 我首先检查了显而易见的部分:容器日志、Vite websocket 消息、绑定挂载路径,以及编辑器是否通过临时文件保存。有用的线索来自于对比 macOS 文件事件与容器内观察到的事件。宿主机能看到每一次保存,但当项目通过嵌套的工作区文件夹挂载时,容器却漏掉了更改。更改轮询设置有所帮助,但这使得开发服务器变得嘈杂且缓慢。 真正有效的方法是将绑定挂载移动到真实的项目路径,从挂载中排除 node_modules,并仅为需要轮询的文件夹设置 Vite 监视轮询。我还添加了一个小脚本,在启动开发服务器之前…

相关公开内容

  1. Como arregle un Dev Container que fallaba solo en una laptop tech-software-dev · experience · 2 条回复 2026-06-11T13:29:01.275Z
  2. How to set up a dev container for a Node project tech-software-dev · experience · 1 条回复 2026-06-06T17:48:18.511Z
  3. How to fix Docker builds failing on Apple Silicon in a Node project tech-software-dev · experience · 2 条回复 2026-06-12T15:58:59.823Z
  4. 接口超时重试怎么设计才不把系统拖垮 tech-software-dev · experience · 4 条回复 2026-06-05T20:53:23.573Z
  5. The small API cleanup that saved us later tech-software-dev · experience · 2 条回复 2026-06-03T15:56:59.439Z
  6. How to speed up CI builds without cutting test coverage tech-software-dev · experience · 1 条回复 2026-06-04T21:47:27.887Z
  7. Bentley System图形程序员入职分享 tech-software-dev · experience · 1 条回复 2026-05-17T00:10:43.701Z
  8. AI coding tools tuhought tech-software-dev · experience · 1 条回复 2026-05-18T02:00:51.998Z
  9. Interviewed for a GPU software engineer role at Sony. Key points: tech-software-dev · experience · 1 条回复 2026-05-20T04:14:38.658Z
  10. Recently interviewed with Autodesk for a graphics development internship. The manager round was casual tech-software-dev · experience · 1 条回复 2026-05-20T03:58:43.093Z