简体   繁体   中英

How to switch compass version?

I have two versions of Compass, 0.12 and 0.13.alpha. The default version is 0.13.alpha but sometimes I need to switch to 0.12.

What command will permit this, please?

old topic, but I just came across the issue of having 2 projects. one using compass version 0.12 and the other 1.0 .

as the newer version of compass relies on a new major release of sass, many deprecation warnings and compatibility issues are experienced when trying to run the newer compass on the old project.


well, now to the solution:

ruby gems already support having multiple versions installed. and after taking a look into the compass executable, it turns out there is a way to specify which compass version to use (the file is generated by rubygems, see http://pastebin.com/HeZnE0T5 if you are curious)

with that we can now have multiple versions of compass installed at once. eg:

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

and now we can use them by specifying which version to use:

$ 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

this obviously also works for other compass commands, eg watch :

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

EDIT: of course the version switch can be done in a Gemfile, but in my case its not a ruby project and compass is started via command line

If you are switching versions for different projects, I recommend using either RVM (Ruby) or virtualenv with some help (Python) or something similar to manage gems and versions. Bundler will help make either solution simpler to maintain.

If you are switching versions within a project, I recommend reconsidering your approach.

This is really simple using bundler.

Install bundler:

$ gem install bundler

Create the Gemfile in your project if you don't already have one:

$ bundle init

Specify the version you want/need in your Gemfile:

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

Install the specific gems and dependencies you have defined in your Gemfile:

$ bundle install

When executing a gem, you can now use bundler to control which version to execute based on your Gemfile:

$ bundle exec compass watch

That's it!

It's helpful to leave a comment in your Gemfile telling other developers how to use bundler:

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

Read more about versioning at http://bundler.io/v1.6/gemfile.html

更改gemfile,添加版本参数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM