Can't @use mixin, but can @import
See original GitHub issueI have a top-level file that only has:
@mixin bg_img($path) {
background-image: url("http://localhost:4102/app/ui/" + $path);
}
If I @import
it, everything is fine. If I @use
it, then it doesn’t come through. For example, this fails, but if I change the @use
to @import
, it succeeds:
@use 'mixins';
.bg {
@include bg_img("photo.jpg");
}
Side point: the file is minimal on purpose - I plan to rewrite it just before running sass
so that the string can be replaced (depending on whether it’s in production or dev environment). Is there a better way to do that?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
SCSS switching from @import to @use: undefined mixin
As I understand the new ruls @use the way, that you have to @use the needed files with the needed mixin to EVERY...
Read more >How to import Sass/SCSS mixins global? - DEV Community
I import the two .scss files in the App.js so I can access the classes/mixins/variables global. But only the classes are accessible.
Read more >mixin and @include - Sass
Mixins allow you to define styles that can be re-used throughout your stylesheet. They make it easy to avoid using non-semantic classes like...
Read more >Sass - Importing files and partials - TutorialsTeacher
But with a few exceptions, you can also nest @import statements. You can't use nested imports within mixins (discussed later in next chapter)...
Read more >Features In-Depth | Less.js
Mixins copy all of the properties into a selector, which can lead to unnecessary duplication. Therefore you can use extends instead of mixins...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m willing to migrate from deprecated
@import
to@use
. I’m sorry if this shouldn’t be posted here, and I’m also sorry if an answer is already given somewhere, but I tried really hard to find it over the internet.So, the question is basically how can I migrate from
to
in Angular 10 app.
The second results in “SassError: This at-rule is not allowed here.”.
The point is that styles in imported stylesheets shouldn’t leak outside of
.my-theme
.My imported stylesheets aren’t mixins, functions or variables. They’re just a bunch of CSS rule-sets. Some of them however could contain varibles, but this is secondary.
One note:
@import
is not deprecated yet. It will be in the future, but at the moment it’s still actively supported. You mention that you’re using Angular, which hasn’t yet migrated to the module system (they’re working on it right now), and we recommend waiting to migrate until all of your dependencies have migrated.When you do migrate, provided you don’t need access to any Sass members, you can use the
meta.load-css
mixin, which loads the CSS rules from a stylesheet without making variables, mixins, or functions accessible. Unlike@use
, it can be used anywhere.