Juicy lil' bytes

Compress Your CSS Output With the SASS Command Line Tool

Here is a one-liner that compiles your SASS or SCSS files into compressed CSS.

Use the following command to install the sass Ruby gem:

gem install sass

Compress Indented Syntax Sass Files

sass -t compressed path/to/input.sass path/to/output.css

Compress Bracketed Syntax SCSS Files

sass --scss -t compressed path/to/input.scss path/to/output.css

or alternatively, you can use the scss command line tool (which is installed with the sass gem) that defaults to the SCSS syntax. This avoids the need for the --scss switch.

scss -t compressed path/to/input.scss path/to/output.css

Use with Compass

If you are using Compass in your project, add the --compass switch to your command so that the Compass imports are available during the compile.

sass -t compressed --compass path/to/input.sass path/to/output.css
scss -t compressed --compass path/to/input.scss path/to/output.css

Create an Alias

Save the command as an alias in your bash startup file (~/.bash_profile or ~/.bashrc) to make it quick and easy to use. Let’s call it ccss for ‘compressed css’:

alias ccss='sass -t compressed --compass --scss'

If you want to use the alias in the open terminal window, run a source command on your bash startup file. For .bash_profile it would look like this: source ~/.bash_profile. You won’t need to do this again the next time that you open the terminal. The alias will automatically load in the new shell process that you launch.

Then use it on the command line by adding your file paths for the input SCSS file and output CSS file:

ccss path/to/input.scss path/to/output.css

Have a look through the SASS documentation on the --watch switch which indicates that sass should watch for changes in your SCSS or SASS files and automatically compile CSS files from the changes. This may be a better fit for your development workflow than these manual compression commands.