Skip to content

Instantly share code, notes, and snippets.

@ecerulm
Last active January 23, 2020 05:47
Show Gist options
  • Save ecerulm/06ba4ee3edc6082cc82f to your computer and use it in GitHub Desktop.
Save ecerulm/06ba4ee3edc6082cc82f to your computer and use it in GitHub Desktop.
Minimal config for sinatra / guard / livereload

Steps

bundle # install the gems bundle exec guard init livereload # to add livereload section to Guardfile bundle exec guard # guard will monitor files mkdir -p public mv index.html public/index.html

Use rackup to start sinatra + rack-livereload

bundle exec rackup config.ru

Open the page in a browser

open http://127.0.0.1:9292/index.html #edit public/index.html and the browser will autoreload

Links

require 'rack-livereload'
require 'sinatra'
use Rack::LiveReload
class MyApp < Sinatra::Application
end
run MyApp
# A sample Gemfile
source "https://rubygems.org"
# gem "rails"
gem 'sinatra'
group :development, :test do
gem 'guard-livereload', require: false
gem 'rack-livereload'
gem 'guard'
end
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>This page will autoreload</title>
</head>
<body>
<p>Change this</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment