配置运行环境

Guard,Compass 和 Livereload 是 Ruby 的 Gem 套件,需要 Ruby 运行环境。另外还需要安装 Ruby 的扩展开发包 Development-Kit,以实现 Livereload 的功能和 SASS 的编译。最后需要 Bundler 用于打包 Gem 依赖。

安装 Ruby

  • 下载并安装 Rubyinstaller
  • 安装过程中勾选相关设置,这样可以直接通过cmd命令行操作(不必手动添加Path)。
  • 安装完成后,在 CMD 窗口运行 ruby --version,若安装成功会显示 Ruby 版本信息。

安装 Development-Kit

  • 下载 Development-Kit
  • 将其解压到某个目录,例如:C:/DevKit/。
  • 打开你的Development-Kit所在的位置,在里面执行以下命令:
ruby dk.rb init
ruby dk.rb install

安装 Bundler

  • 更新 Gem 系统,然后安装 Bundler:
gem update --system
gem install bundler

使用 Bundler 打包所需的 gem 依赖

  • 打开用户目录,增加 Gemfile 和 .Guardfile 这两个文件(文件内容见文末附件)。
  • Shift+右键调出当前目录CMD窗口,运行如下命令:

    bundle
    

Bundler 会根据 Gemfile 中的配置安装 Compass 和 SASS 等 gem,安装过程会比较久,打杯水静静等待 gem 安装完成或执行下一步安装浏览器的 Livereload 插件。

给浏览器安装 Livereload 插件

SafariSafari extension 2.0.9

ChromeChrome extension on the Chrome Web Store

FirefoxFirefox extension 2.0.8

详见 Livereload 的官网:http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-

运行 Guard

  • 在项目目录中运行:guard
  • 打开浏览器,点击浏览器的 Livereload 图标。

至此完成所有的配置,Compass 会检测 Gemfile 定义文件的改动,生成 CSS,并自动刷新浏览器。

附件

以下是 Gemfile 和 .Guardfile 的内容:

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 '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 <.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

最新文章

  1. mysql 5.7.15 vs mysql 5.6.31性能测试以及不同linux内核性能比较
  2. ios 汉字字符串数组拼音排序
  3. Linux之常用快捷键
  4. Shell 语法之函数
  5. WPF基础——Application
  6. Javascript模块化编程(一):模块的写法【转】
  7. 【转】Cygwin访问Windows驱动器
  8. android 在fragment中获取界面的UI组件
  9. PHP检查表单提交是否来自于本站(验证HTTP_REFERER等)
  10. centos下httpd 启动失败的解决办法
  11. sql连接查询中on筛选与where筛选的区别
  12. iOS开发证书都显示“此证书的签发者无效”,更新WWDR Certificate证书后还是显示无效
  13. 封装自定义服务$http
  14. Linux shell 批量运行jmeter脚本
  15. 你真的了解Python吗 ---Python的内存管理
  16. stl算法:next_permutation剖析
  17. hadoop之 参数调优
  18. Object-c 创建按钮
  19. Spring Boot 的彩色日志
  20. iOS 关于Xcode上的Other linker flags

热门文章

  1. php方法----将数组按照键值进行排序
  2. php基础-----常量const和define的区别
  3. 值得尝试的十款 GNOME Shell 扩展
  4. elk集群配置配置文件中节点数配多少
  5. JQuery获取ID含有特殊字符的DOM元素
  6. linux 模块编译步骤(原)
  7. mysql 全表扫描、全索引扫描、索引覆盖(覆盖索引)
  8. java Semaphore信号亮-同意多个任务同一时候訪问这个资源--thinking in java21.7.6
  9. MyEclipse打包可运行的jar包
  10. Android-Volley网络通信框架(自己定义Request 请求:实现 GsonRequest)