Compass is a great framework to use with Sass (which is my favourite CSS-extending language/framework/thing. If you're not using Sass or Less, you should really give it a go - once you've used it on a project you can't imagine writing plain CSS again!). One of the nice things about Compass is that you can set it to watch a folder for changes to the Sass files you're editing, and automatically compile them into CSS.
However, I recently needed to compile only one Sass file into CSS, which meant I couldn't use the 'watch' command (the 'watch' command will overwrite all compiled files if there are changes to the relevant source files; for various reasons, my compiled files were more up-to-date than my source. Which was bad :/ ) so I tried compiling the single Sass file directly.
$ compass compile style.scss
> You must compile individual stylesheets from the project directory
This was slightly confusing - I was in the Sass folder of the project directory, but I still couldn't compile the file. Eventually, I worked out why I couldn't compile - Compass creates a Ruby config file when you initialise it - whichever folder the config file is in is considered the project directory, so make sure you are in the folder with the Ruby config file in it when you try to run the compass compile command. In my case, this was one level above my Sass directory:
$ cd ..
$ compass compile sass/style.scss
> overwrite css/style.css
Success! (I've set up Compass to compile Sass files into a CSS folder). Now I just need to make sure that my source files don't get out of date again...
Using plain Sass
Compiling a single file using plain Sass is slightly more straightforward. Change to the folder containing the file and run sass --watch
:
$ cd myfolder
$ sass --watch style.scss:style.css
where style.scss
is the input file and style.css
is the output file.