live_reload.cr

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

  1. Add the dependency to your shard.yml:

    dependencies:
      live_reload:
        github: bcardiff/live_reload.cr
    
  2. 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

  1. Fork it (https://github.com/bcardiff/live_reload.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

live_reload.cr

Owner
Statistic
  • 10
  • 0
  • 0
  • 2
  • 0
  • about 6 years ago
  • October 1, 2020
License

MIT License

Links
Synced at

Tue, 27 Jan 2026 09:02:30 GMT

Languages