https://github.com/whaaaley/reload-server
https://github.com/whaaaley/reload-server
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/whaaaley/reload-server
- Owner: whaaaley
- License: isc
- Created: 2020-12-26T06:45:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-26T07:10:12.000Z (over 5 years ago)
- Last Synced: 2025-02-08T03:15:42.537Z (over 1 year ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reload-server
> Runs commands when files change then sends an event to the client over SSE.
## TODO
+ Inject reload script into the client server side instead of importing it
+ ESBuild outputs empty app.js files when there's a build error so the client won't auto reconnect (non-issue?)
+ Refine the file extension flag syntax. ex: `--ext:js --ext:css `
+ Use http2?
## Usage
Example using a makefile.
The `--bang` flag runs the following command immediately after the server starts.
Flags like `--js` and `-scss` are flags that correlate to file extensions.
These extension flags can be anything.
```makefile
reload-server \
--bang "$(MAKE) css js html" \
--scss "$(MAKE) css" \
--js "$(MAKE) js" \
--watch "src"
```
Include this in your JavaScript.
```
if (DEV === true) {
const source = new EventSource('/reload')
source.onmessage = body => {
if (body.data === 'connect') {
console.log('Connected to automatic reload')
return // stop execution
}
if (body.data === 'reload') {
window.location.reload()
return // stop execution
}
if (body.data === undefined) {
console.log('Heartbeat from automatic reload')
}
}
}
```