browser-sync - Lite Server 热重载不适用于默认配置

标签 browser-sync lite-server hot-reload

Lite Server 在更改我的 index.html 文件时不会重新加载页面。

我没有使用 bs-config.json 文件。使用以下命令启动 lite 服务器时,我的 index.html 在新选项卡中正确打开:
npm run dev
此控制台信息可能会有所帮助:

> lite@1.0.0 dev C:\test\lite
> lite-server

Did not detect a `bs-config.json` or `bs-config.js` override file. Using lite-server defaults...
** browser-sync config **
{ injectChanges: false,
  files: [ './**/*.{html,htm,css,js}' ],
  watchOptions: { ignored: 'node_modules' },
  server: { baseDir: './', middleware: [ [Function], [Function] ] } }
[Browsersync] Access URLs:
 -------------------------------------
       Local: http://localhost:3000
    External: http://192.168.1.39:3000
 -------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 -------------------------------------
[Browsersync] Serving files from: ./
[Browsersync] Watching files...
19.07.26 21:02:27 304 GET /index.html
[Browsersync] Reloading Browsers...

更改和保存我的 index.html 时,
[BrowserSync] 'Reloading Browsers' 

出现在我的控制台中,但我的页面没有重新加载。
我需要按 F5 然后
19.07.26 21:09:32 200 GET /index.html

出现在我的控制台中。

包.json:
{
  "name": "lite",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
      "dev": "lite-server"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "lite-server": "^2.5.3"
  }
}

如何让 Lite Server 热加载我的页面?

最佳答案

我找到了解决方案

“浏览器同步”仅在有“body”标签时才有效

只需在您的 html 页面中添加 body 标签

关于browser-sync - Lite Server 热重载不适用于默认配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57225897/

相关文章:

浏览器同步 - 从 "node_modules"目录中提供 "src"

node.js - 如何更改 Angular 快速入门中的默认精简服务器端口?

visual-studio-code - VS Code(OSX)Flutter热重载不是由保存触发的

angular - 对于Angular2,为什么具有相同组件的两个页面(两个选项卡)会相互影响?

node.js - Lite-server npm start 不起作用

Flutter 热重载不适用于平板电脑模拟器

Dockerized Vue 应用程序 - 热重载不起作用

sails.js - 获取 livereload 以使用 Sails.js

javascript - 我们应该告诉 browsersync 重新加载特定的资源类型吗?

javascript - Node.js - 开发中的自动刷新