spaaarky21 spaaarky21 - 1 year ago 145
Sass (Sass) Question

SASS: Import a file from a different directory?

In SASS, is it possible to import a file from another directory? For example, if I had a structure like this...

- root_directory
- sub_directory_a
- _common.scss
- template.scss
- sub_directory_b
- more_styles.scss

template.scss could import _common.scss using
@import "common"
but is it possible for more_styles.scss to import _common.scss? I tried a few different things including
@import "../sub_directory_a/common"
@import "../sub_directory_a/_common.scss"
but nothing seems to work.

Answer Source

You could use the -I command line switch or :load_paths option from Ruby code to add sub_directory_a to Sass's load path. So if you're running Sass from root_directory, do something like this:

sass -I sub_directory_a --watch sub_directory_b:sub_directory_b

Then you can simply use @import "common" in more_styles.scss.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download