Compile one SASS to two css with different config from Compass/Codekit

865 views Asked by At

I want to save one SASS file and output two files with different settings, "output_style" and "environment".

Two methods I've experimented with:

  1. Function in the config.rb file to rerun the compress action on the same SASS file with a different extension, but updates the "output_style" and "environment".

  2. Manually save each of the two SASS files, with something in the top of each file that updates the "output_style" and "environment" variables in the config.rb.

I can do this in Grunt, but I'm thinking it'd be nice to just have CodeKit work.

Options, alternatives?

1

There are 1 answers

0
tvl On

Step 1: The development configuration config.rb should look like this:

# Basic configuration.
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "js"

# You can select your preferred output style here (can be overridden via the command line).
# Options: ":expanded", ":nested", ":compact", ":compressed"
output_style = :expanded

# Enable debugging comments that display the original location of your selectors.
line_comments = true

# Re-compile the sass files using the minified configuration.
on_stylesheet_saved do
  `compass compile -c config_minified.rb --force`
end

Step 2: You must add another configuration file config_minified.rb and it should look like this:

# Basic configuration.
http_path = "/"
css_dir = "css/minified"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "js"

# Compressed the output for production.
output_style = :compressed

# Disable debugging comments for production.
line_comments = false

Step 3: Compile as usual and you are ready to go:

compass watch

The /css/minified/style.css will automatically generated.
After you follow these steps the project should looks like this:

/css
/css/style.css
/css/minified/style.css
/images
/sass
/sass/style.scss
config.rb
config_minified.rb

EDIT

If you don't want to mess with relative path per project you can alter the config_minified.rb in order to use a css folder relative to the root folder.

# do not use the css_dir = "css/minified" because it will break the images.
css_dir = "css-minified"