lite-server

Lightweight node server
授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 贾越
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

lite-server

Lightweight development only node server that serves a web app, opens it in the browser, refreshes when html or javascript change, injects CSS changes using sockets, and has a fallback page when a route is not found.

Why

BrowserSync does most of what we want in a super fast lightweight development server. It serves the static content, detects changes, refreshes the browser, and offers many customizations.

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.

Installation and Usage

The recommended installation method is a local NPM install for your project:

npm install lite-server --save-dev
yarn add lite-server --dev # or yarn

...and add a "script" entry within your project's package.json file:

# Inside package.json...
  "scripts": {
    "dev": "lite-server"
  },

With the above script entry, you can then start lite-server via:

npm run dev

Other options for running locally installed NPM binaries is discussed in this Stack Overflow question: How to use package installed locally in node_modules

Using on the fly

lite-server can be used with npx

npx lite-server

Global Installation

lite-server can be also installed globally, if preferred:

npm install --global lite-server

# To run:
lite-server

Custom Configuration

The default behavior serves from the current folder, opens a browser, and applies a HTML5 route fallback to ./index.html.

lite-server uses BrowserSync, and allows for configuration overrides via a local bs-config.json or bs-config.js file in your project.

You can provide custom path to your config file via -c or --config= run time options:

lite-server -c configs/my-bs-config.js

For example, to change the server port, watched file paths, and base directory for your project, create a bs-config.json in your project's folder:

{
  "port": 8000,
  "files": ["./src/**/*.{html,htm,css,js}"],
  "server": { "baseDir": "./src" }
}

You can also provide custom path to your base directory --baseDir= run time options:

lite-server --baseDir="dist"

A more complicated example with modifications to the server middleware can be done with a bs-config.js file, which requires the module.exports = { ... }; syntax:

module.exports = {
  server: {
    middleware: {
      // overrides the second middleware default with new settings
      1: require('connect-history-api-fallback')({
        index: '/index.html',
        verbose: true,
      }),
    },
  },
};

The bs-config.js file may also export a function that receives the lite-server Browsersync instance as its only argument. While not required, the return value of this function will be used to extend the default lite-server configuration.

module.exports = function (bs) {
  return {
    server: {
      middleware: {
        // overrides the second middleware default with new settings
        1: require('connect-history-api-fallback')({
          index: '/index.html',
          verbose: true,
        }),
      },
    },
  };
};

NOTE: Keep in mind that when using middleware overrides the specific middleware module must be installed in your project. For the above example, you'll need to do:

npm install connect-history-api-fallback --save-dev

...otherwise you'll get an error similar to:

Error: Cannot find module 'connect-history-api-fallback'

Another example: To remove one of the default middlewares, such as connect-logger, you can set it's array index to null:

module.exports = {
  server: {
    middleware: {
      0: null, // removes default `connect-logger` middleware
    },
  },
};

A list of the entire set of BrowserSync options can be found in its docs: http://www.browsersync.io/docs/options/

Testing

When using lite-server to run end to end tests, we may not want to log verbosely. We may also want to prevent the browser from opening. These options in the bs-config.js will silence all logging from lite-server:

open: false
  logLevel: "silent",
  server: {
    middleware: {
      0: null
    }
  }

Known Issues

CSS with Angular 2 is embedded thus even though BrowserSync detects the file change to CSS, it does not inject the file via sockets. As a workaround, injectChanges defaults to false.

Contributing

  1. Fork and clone it
  2. Install dependencies: npm install
  3. Create a feature branch: git checkout -b new-feature
  4. Commit changes: git commit -am 'Added a feature'
  5. Run static code analysis and unit tests: npm test
  6. Push to the remote branch: git push origin new-feature
  7. Create a new Pull Request

License

Code released under the MIT license.

  • http://www.litespeedtech.com/litespeed-web-server-downloads.html   负载均衡: http://www.litespeedtech.com/litespeed-load-balancer-downloads.html   php+ruby sapi http://www.litespeedtech.com/php-litespeed-

  • lite-server:node轻服务器,运行打包后的项目; 如果不想自己写node服务就为跑个打包后的项目的话,就用这个吧 更快捷的方式是使用VS Code插件Live Server github地址:lite-server 操作: 1. 创建并进入目录(你想手动创建也行) mkdir LiteServer && cd LiteServer 复制代码 2. 初始化并下载lite-server包

  • Libevent是一个轻量级高效的开源高性能网络库,很多公司都基于该网络库进行开发,我之前参与过的几个的项目客户端的网络底层以及服务端的网络库都是基于该网络库的开发,并且取得良好的性能,并未遇到明显的性能瓶颈。我相信很多大公司也是跟我一样做出相同明智的选择。因此,基于该库进行一系列的扩展也是理所当然。前几天我们客户提出了需求,需要服务器提供http服务,以便接受各种http的请求,这种http请求

 相关资料
  • kafkaUI-lite 是史上最轻便好用的 kafka ui 界面客户端工具,可以在生产消息、消费消息、管理topic、管理group;可以支持管理多个kafka集群 部署简便,可以一键启动,不需要配置数据库、不需要搭建web容器 支持zookeeper ui界面化操作;支持多环境管理 支持redis ui界面化操作;支持多环境管理 支持权限控制,可以自定义不同环境的新增、修改、删除权限;默认分

  • Crawlab 的轻量版本,基于 Golang 的爬虫管理平台,支持任意语言编写的爬虫。 相比较 Crawlab,该版本专注于单机上的爬虫管理,平台运行不依赖任何的外部数据库,去除了大量非必要功能。 快速开始 Docker Compose 1. 在任意目录下创建 docker-compose.yml,内容如下: version: '3'services: master: image: zk

  • Firebug Lite是Firebug的一个子集。值得关注的是Firebug Lite支持IE、Opera和Safari这三款主流浏览器。 Firebug是 站长和博主的必备网络工具。它能对HTML页面的代码进行分析,并能对网页式样元素提供实时预览。另外,它还能对网站的性能进行测试评估,提供对诸如载入 时间等等的分析。 你可以进入Chrome扩展程序中心的Firebug页面进行下载安装Chrom

  • TensorFlow Lite 是一款 TensorFlow 用于移动设备和嵌入式设备的轻量级解决方案。 TensorFlow 可以在多个平台上运行,从机架式服务器到小型 IoT 设备。但是随着近年来机器学习模型的广泛使用,出现了在移动和嵌入式设备上部署它们的需求。而 TensorFlow Lite 允许设备端的机器学习模型的低延迟推断。 设计初衷 轻量级:允许小 binary size 和快速初

  • Paddle Lite为Paddle-Mobile的升级版,定位支持包括手机移动端在内更多场景的轻量化高效预测,支持更广泛的硬件和平台,是一个高性能、轻量级的深度学习预测引擎。在保持和PaddlePaddle无缝对接外,也兼容支持其他训练框架产出的模型。 ## CPU版本安装命令pip install -f https://paddlepaddle.org.cn/pip/oschina/cpu p

  • liteflow是一个基于DAG来实现的分布式任务流调度系统,较azkaban等调度系统,liteflow增加了一些自己的特性: 1.实现任务在任务流间共享 2.任务/任务流的可视化配置 3.一键修复任务/任务流修复提高数据修复效率 4.动态表单+容器机制,提供一个可扩展性比较强的执行引擎 5.执行者可以运行任何类型的任务,java、shell、python等

  • Mockjs Lite,一个极简的仿真数据生成器 特别说明 这个项目参(抄)考(袭)自 Mock.js,但为什么要重复造轮子呢? 因为部分功能不好用,比如没有随机手机号,没有时间区间,占位图不能自己切源,等等。 不够自由,不方便插件化自定义功能,不方便局部定义项目友好的数据。 因为太大了,一个mock而已,为什么要这么大。 因为看了源代码,就想重写了。 好吧,就当是练手了。 PS: 采用 ES6

  • Guns-lite 前言 guns-lite是在guns的基础上开发而来 guns-lite相比guns使用spring data jpa替代了mybatis guns-lite是一个基于spring boot而不是springMVC的后台管理系统。 分支 admin-flat 该分支将guns-admin页面更改为扁平化风格,去掉iframe+标签页的形式: oracle, 该分支将底层数据使用