Import and Module ID’s
-
The problem I thought I was having with @import and @extend is essentially a problem with just @import.
I want an SCSS module that both contains classes and supports other files in being able to extend those classes. I’ve created two files as examples, icons.scss and typography.scss (shown below) as well as third file, icons-and-typography.scss which is just a concatonation of the two. While I can successfully compile the two seperate files locally using ruby gems SASS (libsass) compiler, only the combination file, icons-and-typography.scss, works in the Custom CSS and JS plugin.
Essentially, it seems that the plugin supports SASS identified modules (where an “id” for the file is specified) to have variables, mixins, and placeholders (and thus be used by other modules) but no actual classes. Such classes can be declared but are never generated.
In the example below, when icons.scss is configured with an id, typography.scss won’t compile. Furthermore, I can’t use any of the classes defined in icons.scss. Configured without an id, icons.scss can’t be referenced by typography.scss. Only when they all live in the same file do I have the benefit of both use and reuse.
Being able to keep styles organized is enormously helpful and this issue creates a significant restriction. I appreciate any suggestions.
icons.scss:
.icon-mail { background-image: url("/icons/mail.svg"); position: absolute; top: 0; left: 0; } .icon-mail-blue { @extend .icon-mail; color: blue; } @mixin corner-icon($name, $top-or-bottom, $left-or-right, $color) { .icon-#{$name}-#{$color} { background-image: url("/icons/#{$name}.svg"); position: absolute; #{$top-or-bottom}: 0; #{$left-or-right}: 0; color: #{$color}; } } @include corner-icon("arrow", top, left, "blue");typography.scss
@import 'icons' a[href^="http:"], a[href^="https:"] { @extend .icon-arrow-blue; }Compiling these two files locally using a libSass compiler yields the following CSS:
.icon-mail, .icon-mail-blue { background-image: url("/icons/mail.svg"); position: absolute; top: 0; left: 0; } .icon-mail-blue { color: blue; } .icon-arrow-blue, a[href^="http:"], a[href^="https:"] { background-image: url("/icons/arrow.svg"); position: absolute; top: 0; left: 0; color: blue; }
The topic ‘Import and Module ID’s’ is closed to new replies.