问题
With the new module system in sass (with @use instead of @import) how can i define a class in one file and the use it in another file with @extend ?
File colors.scss
.element {
background-color: blue;
}
main file
@use "./colors.scss" as colors;
body {
@extend .element;
}
This gives the following error:
"body" failed to @extend ".element". The selector ".element" was not found. Use "@extend .element !optional" if the extend should be able to fail.
Example: https://stackblitz.com/edit/angular-tufq7f?file=src%2Fstyles.scss
How can I tell sass to get it from colors.scss?
回答1:
Turns out there are a few different problems here. The first is that the stacblitz example is using an old version of sass witch does not have module support. The other is that there is no way to specify from witch sass module to extend a css class from. The correct solution is what I wrote in the question:
@extend .element;
来源:https://stackoverflow.com/questions/59630514/sass-extend-class-from-module