lite-server

施翰学
2023-12-01

lite-server

轻量级的仅适用于开发 的 node 服务器, 它仅支持 web app, 它能够为你打开浏览器, 当你的html或是JavaScript文件变化时,它会识别到并自动帮你刷新浏览器, 还能使用套接字自动注入变化的CSS, 当路由没有被找到时,它将自动后退页面。

Why

在一个轻量级的开发服务器中,浏览器同步能够支持我们的大多数需求. 它提供静态的内容, 监测文本变化, 刷新浏览器, 并且提供更多自定义功能.

When creating a SPA there are routes that are only known to the browser. For example, /customer/21 may be a client side route for an Angular app. If this route is entered manually or linked to directly as the entry point of the Angular app (aka a deep link) the static server will receive the request, because Angular is not loaded yet. The server will not find a match for the route and thus return a 404. The desired behavior in this case is to return the index.html (or whatever starting page of the app we have defined). BrowserSync does not automatically allow for a fallback page. But it does allow for custom middleware. This is where lite-server steps in.

lite-server is a simple customized wrapper around BrowserSync to make it easy to serve SPAs.

安装与使用

以下是被推荐的安装lite-server的方式:

$ npm install lite-server --save-dev
在你的项目中的  package.json  文件中添加一个 “script” 入口:
# Inside package.json...
  "scripts": {    
    "dev": "lite-server"
  },
  
  
    http://blog.csdn.net/alabadazi/article/details/53334161
     类似资料: