Search code examples
compass-sass

Compass with multiple input/output folders


I'd like to compile/watch Compass/SCSS files, spread over multiple folders, in one command. As far as I know there is no way to configure multiple SCSS folders, coupled with separate CSS output folders.

add_import_path is almost what I need, but I don't see a way to set sass_dir per import path.

Is there a way to do this?
This Quora answer says there is none, but I still have my hopes up :)


Update: Example directory structure:

  • users/user1/css/ <- scss directory
  • users/user1/css/generated/ <- generated css directory
  • users/user2/css/
  • users/user2/css/generated/
  • themes/theme1/css/
  • themes/theme1/css/generated/
  • themes/theme2/css/
  • themes/theme2/css/generated/

Solution

  • I don't know if you want to compile all these scattered SASS files in one compiled CSS. If that's the case I'm afraid I don't know how to help you.

    However, if you want multiple files one possible solution is to use Rake.

    What about wrapping all the watch commands you need in one Rake task, and then executing such task in order to get them running at once.

    Rakefile

    namespace :stylesheets do
      desc 'Watches dynamic stylesheets for user 1 to compile changes'
      task :watch_user1 do
        puts 'Watching first set of stylesheets...'
        system 'compass watch --sass-dir users/user1/css --css-dir users/user1/css/generated -c config/compass.rb'
      end
    
      desc 'Watches dynamic stylesheets for user 2 to compile changes'
      task :watch_user2 do
        puts 'Watching second set of stylesheets...'
         system 'compass watch --sass-dir users/user2/css --css-dir users/user2/css/generated -c config/compass.rb'
      end
      desc 'Watches dynamic stylesheet all to compile changes'
    
      multitask watch_all: ['stylesheets:watch_user1', 'stylesheets:watch_user2'] do
        puts 'watching all...'
      end
    end
    

    Then you just run the multi task rake stylesheets:watch_all and all the sub tasks are issued running their commands in threads.

    This rake tasks can be heavily improved because they are repetitive and through some conventions you could even configure it through .yml files, but hopefully will give you ideas of what you can do with Rake.

    Here some more info on Rake and a nice tutorial about writing rake tasks

    Cheers!