Using Compass in WebStorm

Sass and SCSS extend CSS with variables, mixins, selector inheritance and other nice features that make CSS much friendlier for modern development. The Compass framework is built on Sass, adds a variety of great reusable patterns, and in general makes development with Sass and SCSS much better.

Follow these steps to set up Compass for your project in WebStorm.

First, make sure that Ruby is installed on your computer. Then install Compass (you can totally use the built-in Terminal in WebStorm for that): gem install compass

You can find a little bit more information on Compass installation here: http://compass-style.org/install/

If you’d like to use Compass in the new project, you can run the command: compass init in WebStorm’s Terminal. It will add folders for SCSS and CSS files and create a config.rb file for Compass in the project root.

Now let’s create a new .scss (or .sass) file.

WebStorm will suggest adding a new File Watcher for automatic compilation of SCSS/Sass to CSS. Let’s dismiss this suggestion since we know that we are going to use Compass and it requires different File Watcher.

Type
@import “compass”

WebStorm is not aware of the Compass configuration yet. It will suggest a quick-fix to configure Compass for your project. Press Alt+Enter to apply this quick-fix, or alternatively go to Preferences/Settings | Compass Support to enable Compass Support.

Check Enable Compass.

Important note: Make sure you have the explicit path to the Compass executable file. It should be something like
/Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/bin/compass for Mac,
or
C:\Ruby200\lib\ruby\gems\2.0.0\gems\compass-0.12.2\bin\compass
for Windows.

Now WebStorm will offer you to add File Watcher for Compass. Macros for input and output files paths will be set relative to the config.rb file. You will get compiled CSS files automatically when SCSS (or Sass) is modified.

compass-prompt

If you want to configure Compass for a project with a custom structure where config.rb is not in the project root, you need to make sure that:

  1. The path to the config.rb file in Compass Support settings is correct; and
  2. The path in Arguments input and Output path to refresh in the File Watcher both point to the right locations.

For example, we have a project structure like this:

Then, in the Compass Support settings, the path to config.rb should be:

The File Watcher configuration should be as follows:

If you’ve moved your config.rb and/or folders with CSCC/Sass and CSS files after you had configured Compass once, don’t forget to update paths in config.rb and Compass Support settings and also update paths in the File Watcher.

About Ekaterina Prigara

Ekaterina Prigara is WebStorm product marketing manager at JetBrains. She's passionate about new technologies, UX and coffee.
This entry was posted in Cool Feature, Tutorials. Bookmark the permalink.

4 Responses to Using Compass in WebStorm

  1. I’ve been setting up WebStorm 7 with absolutely no issues whatsoever when initializing Compass. I have just downloaded the new version (8) and when I run “compass init” from the terminal window of a new project I get:

    C:\Users\kstirnkorb\WebstormProjects\TestProject>compass init
    directory sass/
    directory stylesheets/
    create config.rb
    Errno::EACCES on line ["897"] of C: Permission denied – (C:/Users/kstirnkorb/WebstormProjects/TestProject/config.rb20140328-8100-ppoa0c, C:/Users/kstirnkorb/WebstormProjects/TestProject/config.rb)

    So I don’t know what to do. Can you please advise? Is this possibly a bug with the latest version?

    Thanks!

    Kurt Stirnkorb

  2. Dennis Erny says:

    Thanks for this….

    I do have a question though and that is how to get Live Edit (using the Chrome connector plugin) to automatically update the browser when a Sass file is changed and compiled to CSS. My Compass file watcher works fine and I have set the refresh directory to the folder containing the final CSS but the changes do not get reflected in Chrome.

    Any thoughts?

    Cheers,
    Dennis

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>