Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>watch-file-refresh-pageNew to Visual Studio Code? Get it now.
watch-file-refresh-page

watch-file-refresh-page

ZhengWei513

|
1 install
| (0) | Free
原生 js 项目, 监听文件(html, css, js)修改, 通过 SSE 通知前端, 实现自动刷新页面
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

原生 js 项目, 监听文件(html, css, js)修改, 通过 SSE 通知前端, 实现自动刷新页面

工作区 .vscode 目录下 settings.json 配置

"watchFile.config": {
  "watchFileType": ["js", "html", "css"], // 监听的文件类型
  "port": 6006, // 默认 6006
  "autoStart": false, // 默认不启动
}

页面添加代码

// ! 实例代码
{
  if (['127.0.0.1', 'localhost', '${localIp}'].includes(location.hostname)) {
    new EventSource('http://${localIp}:${port}/sse').onmessage = (e) => location.reload();
  }
}
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft