Skip to content Skip to sidebar Skip to footer

Import Common Modules By Default When Compiling Scss

I have several modules that contain things like border-radius, $btnBgColor, up-arrow. Most of the other modules need to import them in one place or another, so I'm wondering if I c

Solution 1:

Yes, this is indeed possible and in fact there is already an existing mature solution.

It's called Compass.

There's a lot of ambiguity about what Compass is, here's my kinda non-canonical attempt to resolve it.

Compass is three different things under one name:

  1. A standard for creating reusable SASS modules, just like you want. Those modules are called "Compass extensions". Compass extensions are basically pieces of SASS code organized in a certain manner, distributed as Ruby gems. They can also contain Ruby code used to introduce custom SASS functions.
  2. A compass command-line tool used to compile SASS with support for those extensions. Note that it's just a wrapper for the original SASS compiler, not an independent compiler. Here are its major features:
    • compass allows importing extensions using only their names and omittng paths, e. g. @import singularity.
    • Relies on the config.rb configuration file. config.rb is a piece of Ruby code. The best thing about it is that you can declare custom SASS functions with the powerful Ruby!
    • It also imposes certain file/folder structure for your SASS projects, called "a Compass project". A very basic Compass project consists of a config file, a folder for SASS code and a folder for resulting CSS code. Some Compass extensions contain templates that allow you create new Compass projects with somewhat more advanced structure (i recommend the Toolkit extension).
  3. A Compass extension of the same name (i. e. @import compass in SASS) that contains a lot of invaluable SASS mixins and functions.

If you're going to create a Compass extension for your needs, you can use this as a starter kit (note that the word "template" in the name of the starter kit means a different thing than above).

PS You're using pyScss, it claims to have full support for Compass. Yet, i consider this to be a kinda poor practice. I would rather use native SASS and Compass software. With such Ruby tools as RVM, RubyGems and Bundler, it's very simple to do and to maintain, even when your project is not in Ruby. The complexity of your project increases, but it pays you off with the simplicity of using native tools rather than some dubious ports. Also see How to use Compass/Sass with Django.

Also have a look at Grunt and Yeoman, which are considered to be the most modern practices that improve your development workflow.

References

Post a Comment for "Import Common Modules By Default When Compiling Scss"