<commit_before># light-server

A lightweight cli static http server and it can watch files, execute commands and trigger livereload.

## Why light-server?

When I was writing some simple static web apps, it was helpful to have some tools to serve static http, to watch files and run command, and to trigger refresh in browser.

I think the scenario is not too complicated, so I don't want to use heavy tools like grunt or gulp. IMO, npm script with cli tools is already enough.

Here is an [article](http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/) about using npm to replace grunt/gulp, I really like it.

There are many existing tools in npm, but I could not find one to do all the things for me. Well, actually browser-sync is one, but it offers too many features I don't need, and its installation time is really, unacceptable.

Not lucky enough :(

Then I wrote light-server, with the following features:
* A simple static http server
* Watch files, support multiple glob expressions
* Trigger custom command if watched files change
* Trigger browser reload if watched files change
* Trigger css reload without refreshing page
* Live reload does not require any setup, and even works on smart phones
* Auto inject client reload javascript in html, no need to manually add
* Live reload websocket server uses the same port as http server
* Proxy to another http server

And now my package.json is simpler and cleaner than before :)

## Install

light-server has much smaller footprint, compared to browser-sync, so it is recommended to install in project level, and use it with npm script.

```bash
$ npm install light-server
```
Of course, you can install it globally, too.

## Usage

```
Usage: light-server [options]

Options:

  -h, --help                      output usage information
  -V, --version                   output the version number
  -s, --serve <directory>         serve the directory as static http
  -p, --port <port>               http server port, default 4000
  -b, --bind <bind>               bind to a specific host, default 127.0.0.1
  -w, --watch <files to watch>    files to watch, in glob format, repeatable
  -c, --cmd <command>             if watched files changed, trigger the command
  -i, --interval <watch inteval>  interval in ms of watching, default 500
  -d, --delay <livereolad delay>  delay in ms before triggering live reload, default 0
  -x, --proxy <upstreamurl>       when file not found, proxy the request to another server
  -q, --quiet                     quiet mode with minimum log message

Examples:

  $ light-server -s . -p 7000
  $ light-server -s . -w "*.js, src/** # npm run build && echo wow!"
  $ light-server -s . -x http://localhost:8000
  $ light-server -s . -b 10.0.0.1
  $ light-server -x http://localhost:9999 -w "public/**"
  $ light-server -s static -w "**/*.css # # reloadcss"

Watch expression syntax: "files[,files] # [command to run] # [reload action]"
  3 parts delimited by #<commit_msg>correct README.md<commit_after># light-server

A lightweight cli static http server and it can watch files, execute commands and trigger livereload.

## Why light-server?

When I was writing some simple static web apps, it was helpful to have some tools to serve static http, to watch files and run command, and to trigger refresh in browser.

I think the scenario is not too complicated, so I don't want to use heavy tools like grunt or gulp. IMO, npm script with cli tools is already enough.

Here is an [article](http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/) about using npm to replace grunt/gulp, I really like it.

There are many existing tools in npm, but I could not find one to do all the things for me. Well, actually browser-sync is one, but it offers too many features I don't need, and its installation time is really, unacceptable.

Not lucky enough :(

Then I wrote light-server, with the following features:
* A simple static http server
* Watch files, support multiple glob expressions
* Trigger custom command if watched files change
* Trigger browser reload if watched files change
* Trigger css reload without refreshing page
* Live reload does not require any setup, and even works on smart phones
* Auto inject client reload javascript in html, no need to manually add
* Live reload websocket server uses the same port as http server
* Proxy to another http server

And now my package.json is simpler and cleaner than before :)

## Install

light-server has much smaller footprint, compared to browser-sync, so it is recommended to install in project level, and use it with npm script.

```bash
$ npm install light-server
```
Of course, you can install it globally, too.

## Usage

```
Usage: light-server [options]

Options:

  -h, --help                           output usage information
  -V, --version                        output the version number
  -s, --serve <directory>              serve the directory as static http
  -p, --port <port>                    http server port, default 4000
  -b, --bind <bind>                    bind to a specific host, default 127.0.0.1
  -w, --watchexp <watch expression>    watch expression, repeatable
  -i, --interval <watch inteval>       interval in ms of watching, default 500
  -d, --delay <livereolad delay>       delay in ms before triggering live reload, default 0
  -x, --proxy <upstreamurl>            when file not found, proxy the request to another server
  -q, --quiet                          quiet mode with minimum log message

Examples:

  $ light-server -s . -p 7000
  $ light-server -s . -w "*.js, src/** # npm run build && echo wow!"
  $ light-server -s . -x http://localhost:8000
  $ light-server -s . -b 10.0.0.1
  $ light-server -x http://localhost:9999 -w "public/**"
  $ light-server -s static -w "**/*.css # # reloadcss"

Watch expression syntax: "files[,files] # [command to run] # [reload action]"
  3 parts delimited by #
{'fraction_non_alphanumeric': 0.08336151504903619, 'fraction_numerical': 0.010821778829895164, 'mean_word_length': 3.0020297699594045, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '846699', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1575, 'n_words': 830}