Created
August 24, 2011 01:01
-
-
Save courtsimas/1167053 to your computer and use it in GitHub Desktop.
@import-once hack for sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sessions.css.scss - file #1 that i only want to let the _style.scss import be included once | |
$imported-once-files: (); | |
@function import-once($name) { | |
@if index($imported-once-files, $name) { | |
@return false; | |
} | |
$imported-once-files: append($imported-once-files, $name); | |
@return true; | |
} | |
@import "style"; | |
body.sessions { | |
//normal css for the sessions pages | |
} | |
///////// | |
//donations.css.scss - file that i only want to have _style.scss included once, but if it was already included in sessions, dont double include it | |
$imported-once-files: (); | |
@function import-once($name) { | |
@if index($imported-once-files, $name) { | |
@return false; | |
} | |
$imported-once-files: append($imported-once-files, $name); | |
@return true; | |
} | |
@import "style"; | |
body.donations { | |
//normal css for the donations pages | |
} | |
////////// | |
//_style.scss shared file with base styles | |
@if import-once("_style.scss"){ | |
//base styles and declarations of cool sass-iness that you only want included once | |
} |
Related to sass/sass#139 , they have been considering this for 4 years. Such a pity it's not there yet, it'd be really helpful something like this:
@import "style" !once;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's a shame we need to use crazy hacks like these to do something as basic as conditional loading of
@import
files.Note that the core dev team is reluctant to implement this feature, although they are considering the implementation of a brand new dependency system.
See the following Github issues :