Guard,Compass 和 Livereload 是 Ruby 的 Gem 套件,須要 Ruby 運行環境。另外還須要安裝 Ruby 的擴展開發包 Development-Kit,以實現 Livereload 的功能和 SASS 的編譯。最後須要 Bundler 用於打包 Gem 依賴。php
ruby --version
,若安裝成功會顯示 Ruby 版本信息。ruby dk.rb init
ruby dk.rb install
gem update --system
gem install bundler
Shift+右鍵調出當前目錄CMD窗口,運行以下命令:css
bundle
Bundler 會根據 Gemfile 中的配置安裝 Compass 和 SASS 等 gem,安裝過程會比較久,打杯水靜靜等待 gem 安裝完成或執行下一步安裝瀏覽器的 Livereload 插件。html
Safari:Safari extension 2.0.9git
Chrome:Chrome extension on the Chrome Web Storegithub
Firefox:Firefox extension 2.0.8web
詳見 Livereload 的官網:http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-chrome
guard
。至此完成全部的配置,Compass 會檢測 Gemfile 定義文件的改動,生成 CSS,並自動刷新瀏覽器。瀏覽器
如下是 Gemfile 和 .Guardfile 的內容:sass
Gemfileruby
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 '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
.Guardfile
# More info at https://github.com/guard/guard#readme notification :off # 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 # If current or child directories has files we want to monitor for live changes. # This may throw an error with ruby < 1.9. require 'find' if Find.find(Dir.pwd).detect{|dir|dir=~/.+\.(css|js|html?|php|inc)$/} # https://github.com/guard/guard-livereload guard 'livereload' do watch(%r{.+\.(css|js|html?|php|inc)$}) end end