github.com/bcardiff/live_reload.cr
0.1.0 / published Oct 1, 2020 / repository
A LiveReload server implementation in Crystal
LiveReload.cr
This is a LiveReload server implementation in Crystal.
It creates an HTTP server at http://0.0.0.0:35729 that serves the /livereload.js script and handles official-7 protocol via websocket.
Currently, it does not watch the filesystem for changes. You can use bcardiff/crystal-fswatch or petoem/inotify.cr and trigger a LiveReload::Server#send_reload.
Installation
-
Add the dependency to your
shard.yml:dependencies: live_reload: github: bcardiff/live_reload.cr -
Run
shards install
Usage
require "live_reload"
require "fswatch"
dir = Dir.current
live_reload = LiveReload::Server.new
FSWatch.watch dir do |event|
live_reload.send_reload(path: event.path, liveCSS: event.path.ends_with?(".css"))
end
puts "Watching changes from #{dir}"
puts "LiveReload on http://#{live_reload.address}"
live_reload.listen
Contributing
- Fork it (https://github.com/bcardiff/live_reload.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Brian J. Cardiff - creator and maintainer