星期一, 10月 29, 2012

在Linux使用Guard-LiveReload

因為 LiveReload 的App並不支援Linux,所以也必須手動安裝。此處我就以 Ubuntu/Mint來安裝。



首先,把需要的套件裝齊,gcc和ruby。
$sudo apt-get install build-essential ruby1.9.1 ruby 1.9.1-dev

許多高手在Linux/Mac會用rvm,因為我不是高手,也不寫RoR,所以只用系統提供的Ruby。

接下來,就是安裝livereload及guard-livereload,不囉唆,一次裝完 :D
$sudo gem install livereload guard-livereload  yajl-ruby bundler rb-inotify compass $compass-validator css_parser

如果需要用Rails,得先裝sqlite3及Node.js
$sudo apt-get install sqlite3 libsqlite3-dev node
$sudo gem install sqlite3 rails therubyracer

接下來和Windows一樣,做一個Gemfile,內容:
source "http://rubygems.org"
group :development do
  gem 'compass'            # Depends on Sass, will be installed automatically.
  gem 'compass-960-plugin' # 960.gs
  gem 'compass-validator'  # So you can `compass validate`.
  gem 'rb-inotify', '~> 0.8.8'
  gem 'oily_png'           # Faster Compass sprite generation.
  gem 'css_parser'         # Helps `compass stats` output statistics.
  gem 'guard-compass'      # Compile on sass/scss change.
  gem 'guard-livereload'   # Browser reload.
  gem 'yajl-ruby'          # Faster JSON with LiveReload in the browser.
end
接下來跑一遍bundler,確認沒少東西。
$bundle
剩下來就是監控檔config.rb及Guardfile
config.rb
http_path = "/"
css_dir = "css"
sass_dir = "css"
images_dir = "images"
javascripts_dir = "js"
preferred_syntax = :scss
line_comments = false #不要產生註解
Guardfile
notification :on
# Current watch directory must contain the Compass config file.
if File.exists?("./config.rb")
  # https://github.com/guard/guard-compass
  guard 'compass' do
    watch(%r{(.*)\.s[ac]ss$})
  end
end

guard 'livereload' do
  watch(%r{.+\.(css|js|aspx|ashx|html|php|inc)$})
end
沒問題就可以在監控目錄跑
$bundle exec guard

沒有留言: