Rename CSS on Compile

Filed under: web Tagged: SASS and compass
17 May, 2013

I've always wondered if there was automated way to add the .min to production CSS files on compile when using Compass. It just so happens this tiny bit of ruby will do the trick for you.

require "fileutils"
on_stylesheet_saved do |file|
  if File.exists?(file)
    filename = File.basename(file, File.extname(file))
    File.rename(file, css_dir + "/" + filename + ".min" + File.extname(file))

By hooking the on_stylesheet_saved compass callback we can gain access to the filename and then we can use that to do our work. For a list of other callbacks and options from compass see the configuration reference.

comments powered by Disqus