Skip to content

Instantly share code, notes, and snippets.

@noniq
Created February 5, 2012 17:32
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save noniq/1746744 to your computer and use it in GitHub Desktop.
Save noniq/1746744 to your computer and use it in GitHub Desktop.
Script for building a single giant compass-all.scss file.
# Usage:
# ruby concat.rb /path-to-compass-gem/frameworks/compass/stylesheets/_compass.scss > compass-all.scss
@seen = []
def concat(file)
File.foreach(file) do |line|
if line =~ /^\s?@import "(.+?)";/
import = $1
unless @seen.include?(import)
@seen << import
puts "// IMPORTING #{import}"
import_filename = import.gsub(%r{([^/]+)$}, '_\1.scss')
import_path = File.exist?(File.dirname(file) + "/" + import_filename) ? File.dirname(file) : @basedir
concat("#{import_path}/" + import_filename)
end
else
puts line
end
end
end
@basedir = File.dirname(File.expand_path(ARGV[0]))
concat ARGV[0]
@intellix
Copy link

Damn, this has made things SO much quicker. Thank you so much. I've gone from waiting 4-5 seconds per compile to 0.5s or so.

@ain
Copy link

ain commented Nov 1, 2013

Have you used this script in a Grunt/Yeoman setup? Any experience using this with grunt-contib-compass?

@alexdpunkt
Copy link

I just tried it. Made me only 1 second faster, compass:server still takes about 5 seconds :-(

@ChristiaanScheermeijer
Copy link

I just used this script for a Grunt/Yeoman project and reduced the build time to 1.1s ! Before it took 6+ seconds between save and live reload.

Thanks!

@polikin
Copy link

polikin commented Apr 24, 2014

How can I use it with my Grunt project?

@adrianjacob
Copy link

I have created concat.rb in C:\Ruby193\lib\ruby\gems\1.9.1\gems\compass-core-1.0.0.alpha.19\stylesheets and then tried to run 'ruby concat.rb' in the terminal but I receive the following: C:\Ruby193\lib\ruby\gems\1.9.1\gems\compass-core-1.0.0.alpha.19\stylesheets>ruby
concat.rb
concat.rb:20:in expand_path': can't convert nil into String (TypeError) from concat.rb:20:in

'

Am I missing something? (I'm new to Ruby)

@moritzjacobs
Copy link

If you're interested in a quick and dirty benchmark, I just compared the following grunt setups:

Before: grunt-contrib-compass / @include "compass/compass":

Completed in 3.966s …
Completed in 3.924s …
Completed in 4.013s …

Bypass lib but compile with compass: grunt-contrib-compass / @include "vendor/compass-all":

Completed in 2.899s …
Completed in 3.098s …
Completed in 2.899s …

Use SASS, bypass compass completely: grunt-contrib-sass / @include "vendor/compass-all":

Completed in 0.866s …
Completed in 0.816s …
Completed in 0.834s …

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment