【问题标题】:How to switch compass version?如何切换指南针版本?
【发布时间】:2012-09-16 22:51:28
【问题描述】:

我有两个版本的 Compass,0.12 和 0.13.alpha。默认版本是 0.13.alpha 但有时我需要切换到 0.12。

请问什么命令允许这样做?

【问题讨论】:

  • 没有必要给大家投反对票。对我来说似乎是一个合法的问题。

标签: ruby gem sass compass-sass


【解决方案1】:

老话题,但我刚刚遇到了有 2 个项目的问题。一个使用指南针版本0.12,另一个使用1.0。

由于较新版本的 compass 依赖于 sass 的新主要版本,因此尝试在旧项目上运行较新的 compass 时会遇到许多弃用警告和兼容性问题。


好吧,现在解决方法:

ruby gems 已经支持安装多个版本。在查看了compass 可执行文件后,发现有一种方法可以指定要使用的指南针版本(该文件由 ruby​​gems 生成,如果您好奇,请参阅http://pastebin.com/HeZnE0T5)

这样,我们现在可以一次安装多个版本的指南针。例如:

gem install compass -pre // currently version 1.0.0.alpha.19
gem install compass // currently version 0.12.6

现在我们可以通过指定要使用的版本来使用它们:

$ compass version
Compass 1.0.0.alpha.19
Copyright (c) 2008-2014 Chris Eppstein
Released under the MIT License.
Compass is charityware.
Please make a tax deductable donation for a worthy cause: http://umdf.org/compass

$ compass _0.12.6_ version
Compass 0.12.6 (Alnilam)
Copyright (c) 2008-2014 Chris Eppstein
Released under the MIT License.
Compass is charityware.
Please make a tax deductable donation for a worthy cause: http://umdf.org/compass

这显然也适用于其他指南针命令,例如watch:

$ compass _0.12.6_ watch .
>>> Compass is watching for changes. Press Ctrl-C to Stop.

编辑:当然版本切换可以在 Gemfile 中完成,但在我的情况下,它不是 ruby​​ 项目,并且指南针是通过命令行启动的

【讨论】:

    【解决方案2】:

    如果您要为不同的项目切换版本,我建议使用 RVM (Ruby) 或 virtualenv 和 some help (Python) 或类似的东西来管理 gem 和版本。 Bundler 将有助于使任一解决方案更易于维护。

    如果您在项目中切换版本,我建议您重新考虑您的方法。

    【讨论】:

      【解决方案3】:

      使用 bundler 真的很简单。

      安装捆绑器:

      $ gem install bundler
      

      如果您还没有 Gemfile,请在您的项目中创建:

      $ bundle init
      

      在您的 Gemfile 中指定您想要/需要的版本:

      gem 'compass', '~>0.12.2'
      gem 'sass', '3.2.8'
      

      安装您在 Gemfile 中定义的特定 gem 和依赖项:

      $ bundle install
      

      在执行 gem 时,您现在可以使用 bundler 根据您的 Gemfile 控制要执行的版本:

      $ bundle exec compass watch
      

      就是这样!

      在您的 Gemfile 中留下评论告诉其他开发人员如何使用 bundler 会很有帮助:

      # Now that you're using Bundler, you need to run `bundle exec compass watch` instead of simply `compass watch`.
      

      在http://bundler.io/v1.6/gemfile.html阅读有关版本控制的更多信息

      【讨论】:

        【解决方案4】:

        更改 gemfile,添加版本参数。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-27
          • 1970-01-01
          • 2011-03-06
          • 2014-01-05
          • 1970-01-01
          • 2014-09-25
          相关资源
          最近更新 更多