https://github.com/jamen/serve-dev
ZEIT's serve with auto-reloading and GNU Make rebuilding.
https://github.com/jamen/serve-dev
Last synced: about 1 year ago
JSON representation
ZEIT's serve with auto-reloading and GNU Make rebuilding.
- Host: GitHub
- URL: https://github.com/jamen/serve-dev
- Owner: jamen
- License: mit
- Created: 2019-04-27T18:14:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-27T18:14:39.000Z (about 7 years ago)
- Last Synced: 2025-02-08T02:24:04.836Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# serve-dev
ZEIT's [serve](https://github.com/zeit/serve) made with auto-reloading and GNU Make rebuilding.

## Install
```
npm i @jamen/serve-dev
```
## Usage
### `serve-dev [public] [options]`
Starts a static file serve with optional rebuilding and auto-reloading.
The available options are:
- `--listen ` Specifies where the server listens from. Its the same as `serve`.
- `--config ` Loads a JSON file of `serve-handler` options.
- `--watch ` A file, directory, or glob pattern where the server watches files.
- `--make ` A make target that corrosponds to a watcher.
- `--https` Enables HTTPS. Uses `--key` and `--cert`.
- `--program ` Use something other than `make` for building.
- `--reload ` The server endpoint where reload events are pushed.
### Auto-reloading
In order for auto-reloading to work, your application needs to support it. This is demonstrated in the code below.
```js
let src
(function connect (reconnect) {
src = new EventSource('/__reload')
src.onopen = () => reconnect && window.location.reload()
src.onmessage = () => window.location.reload()
src.onerror = () => setTimeout(() => connect(true), 3000)
})()
window.addEventListener('beforeunload', () => {
if (src && src.readyState < 2) {
src.close()
}
})
```
[A bug](https://bugzilla.mozilla.org/show_bug.cgi?id=833462) with Firefox makes the `beforeunload` event listener necessary.