-
-
Save courtsimas/1167053 to your computer and use it in GitHub Desktop.
//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 | |
} |
Hi Jonathan, I still don't follow how I can use sass-import-once to avoid duplication.
Thanks, this helped me a lot while combining several independent modules into a combined layout CSS. I added !default to $imported-once-files so I only need to define the function once.
OMFG! You just saved my life! Placeholders are atrocious if they get imported twice.
I'm totally now using this on JSMACSS!!!! Thank you!
Hey, I just published a gem which makes import once the default behaviour. Would love to hear what you guys think. Here it is: https://github.com/theblacksmith/sass-import_once
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 :
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;
This is genius! Good job :)