⇤ home

Capistrano task for LESS CSS (with Asset Packager)

Posted 14 Oct 2009 in Programming and Ruby on Rails

As I´m using the Asset Packager plugin to minify and merge Javascript in a project that I currently work on, some additional tasks needed to be added to generate the CSS from LESS CSS before merging into packages. You simply need the following tasks for it to work or you´ll hit dependency problems.

# lib/tasks/less.rake

namespace :less do
  desc 'Updates stylesheets if necessary from their LESS CSS templates.'
  task :update => :environment do
    Less::More.clean
    Less::More.parse if Less::More.page_cache?
  end
end

# config/deploy.rb

namespace :less do
  desc 'Updates the stylesheets generated by LESS CSS'
  task :update do
    run "cd #{release_path} && rake less:update RAILS_ENV=production"
  end
end

after "deploy:update_code", "deploy:create_asset_packages"
before "deploy:create_asset_packages", "less:update"

Remember to have the LESS gem installed on the server. The LESS CSS Rails plugin called “more” is used in the above example.

Update: Michael Deering had a similar problem using SASS.

Related Posts