htmlcssruby-on-railssasscompass

Convert a single Scss file to CSS using compass-watch


I am tired to convert Scss modules to CSS one by one manually. I just want to convert my individual Scss file from many modules. I am using compass watch on command line based compiling CSS through ruby on rails service for compass.

Here you can see how I am managing Scss to CSS conversion through ror cli.cli compass watch


Solution

  • You can create a scss or sass file where you will import all partials.

    Example: create a sass file inside your sass directory and name it as you want, maybe app.sass.

    Inside app.sass, import all you partials like so: @import 'partials/button-actions'

    Create config.rb in the directory where you starting watcher. I prefer to use the project root directory.

    Inside config.rb insert:

    require 'compass/import-once/activate'
    # Require any additional compass plugins here.
    
    # Set this to the root of your project when deployed:
    # Change paths to yours. css_dir is css output directory, sass_dir is your sass file directory
    http_path = "/"
    css_dir = "css"
    sass_dir = "sass"
    images_dir = "i"
    javascripts_dir = "js"
    
    # You can select your preferred output style here (can be overridden via the command line):
    # output_style = :expanded or :nested or :compact or :compressed
    output_style = :compressed
    
    # To enable relative paths to assets via compass helper functions. Uncomment:
    # relative_assets = true
    
    # To disable debugging comments that display the original location of your selectors. Uncomment:
    # line_comments = false
    
    
    # If you prefer the indented syntax, you might want to regenerate this
    # project again passing --syntax sass, or you can uncomment this:
    preferred_syntax = :sass
    # and then run:
    # sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
    

    And start watcher. You will get an app.css file which contains all the code from the imported files as the result. Import it into your HTML.