Thomas Taylor Thomas Taylor - 1 year ago 107
Sass (Sass) Question

Compress non digested SASS assets rails

I have some assets that I need to keep out of the asset pipeline but still need to be compressed, specifically some SASS files. I have achieved this for my non digested JS which looks something like this:

Dir["#{Rails.root}/app/assets/javascripts/non_digest/*"].each do |asset|
asset_name = File.basename(asset)
asset_output = "#{Rails.root}/public/external/#{asset_name}"
asset_uglified = Uglifier.compile(, 'w') {|a| a.write(asset_uglified) }

This is included in my initializers.

Is it possible to use Sprockets to do the same for my non digested SASS files? I've taken a quick look at
but haven't been able to get it to work so far.

Answer Source

If you have the sass gem installed you can do the following:

Dir["#{Rails.root}/app/assets/stylesheets/non_digest/*"].each do |asset|
  asset_name = File.basename(asset)
  asset_output = "#{Rails.root}/public/external/#{asset_name.gsub('.scss', '.css')}"
  asset_minified =, syntax: :scss, style: :compressed).render, 'w') {|a| a.write(asset_minified) }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download