2021 update
The Sass team discourages the continued use of the @import rule. Sass will gradually phase it out over the next few years, and eventually remove it from the language entirely. Prefer the @use rule instead.
So as per the situation here , the code should be changed from
@import 'path/to/main.scss' //Note: make sure that you name your sass partials starting with an underscore(_), this way sass knows that its not meant to be compiled to a css file and you also don't need to include the extension as seen here, instead change it
to
@use 'path/to/main' as m //where 'm' is a reference variable or namespace to your partial.which BTW is optional but recommended.
You can find more about it here: Sass-docs/imports
Answer from shaderone on Stack Overflow2021 update
The Sass team discourages the continued use of the @import rule. Sass will gradually phase it out over the next few years, and eventually remove it from the language entirely. Prefer the @use rule instead.
So as per the situation here , the code should be changed from
@import 'path/to/main.scss' //Note: make sure that you name your sass partials starting with an underscore(_), this way sass knows that its not meant to be compiled to a css file and you also don't need to include the extension as seen here, instead change it
to
@use 'path/to/main' as m //where 'm' is a reference variable or namespace to your partial.which BTW is optional but recommended.
You can find more about it here: Sass-docs/imports
at the top of your SASS file (action-sheet-layout-1.scss) you need to include: @import "../../../theme/main.scss" then you can access the mixins inside main.scss by doing @include settingAnimationHeader; inside the css rule where you want to apply this mixin
Can i use mixins defined in a partial that is imported in the main scss file in another partial?
Can't @use mixin, but can @import
gulp - Can SASS mixins and variables sit in different files? - Stack Overflow
sass - import content of scss file using mixin - Stack Overflow
Videos
I have three files:
-
style.scss
-
_mixins.scss
-
_navigation.scss
obviously, in _mixins.scss i have my mixins defined. In style.scss i then import these mixins with u/use 'mixins';. I now also have another partial called _navigation.scss that i also imported into the main scss file using u/use 'navigation';. I now want to use a mixin defined in the mixins partial, in the navigation partial. But when i try to do this i get an Error: Undefined mixin.
Is what i am trying to do not possible? If so, how would i use a mixin defined in _mixins.scss in another partial?
The short answer is you dont have to import them into everyfile that might include them. However there does need to be a relationship somewhere, and how you do this depends on whether or not you are looking to build one single final CSS file - or a series of individual files.
If you want the former, you could consider having a master import file that does little more than import all the appropriate *.scss files, and have this be the main SASS file your gulp build script looks to compile.
You'll need to take care to import files in the correct order - so no importing a file that uses a mixin before the file that defines the mixin has been imported it's self.
So for example - personally I work with a main.scss file that is structured as
@import "common/_variables.scss";
@import "common/_mixins.scss";
// Now import the files that might use these vars/mixins
@import "common/_buttons.scss";
which is built via gulp to create css/main.css.
Should you want a series of CSS files - i.e. buttons.css, type.css, layout.css etc - then you would need to have the appropriate variables and mixin @import declarations in each file that calls them
I found the best solution for me with pre-concating SASS files with GULP.
Like in this example for STYLUS
gulp.src(config.projects.css.source)
.pipe(sourcemaps.init())
.pipe(mktimecss(__dirname+'/web'))
.pipe(concat('styles'))
.pipe(stylus({
'include css': true,
use: [nib()],
// compress: true,
linenos: false
}))
...... and so on .......
This is how you can implement mixin in your scss file:
@mixin mobile-md {
@media (min-width: #{$breakpoint-mobile + 80}) {
@content;
}
}
And this is how you can use it in your code:
@include mobile-md {
// Styles for screens larger than the mobile-md breakpoint
}
Let's understand all about mixin:
The provided code snippet is written in SCSS (Sassy CSS) and defines a mixin called mobile-md. A mixin in SCSS is a reusable block of code that can be included in other stylesheets using the @include directive.
Here's a breakdown of what the code does:
@mixin mobile-md { ... }: This line defines a mixin named mobile-md.
@media (min-width: #{$breakpoint-mobile + 80}) { ... }: This line specifies a media query that targets a minimum width equal to the value of the variable $breakpoint-mobile plus 80. The min-width condition is used to apply the styles within the media query only if the viewport width meets the specified criteria.
@content;: This line is a placeholder that will be replaced with the actual content of the mixin when it is included in other stylesheets using @include.
To better understand the code, we need to know the value of the variable $breakpoint-mobile. It seems that the value of this variable is expected to be a number representing a specific mobile breakpoint. The mixin mobile-md is intended to apply styles when the viewport width is larger than the mobile breakpoint plus 80 pixels.
By utilizing the mobile-md mixin with appropriate styles inside the @media block, you can create responsive designs that adapt to different screen sizes.

You don't want a class selector in your mixin.
That's why it's not applied.
@mixin special-button {
background: $nav-background;
height: 2.5em;
border-radius: .8rem;
}
Change your mixin to the above and it will work. You almost had it. The way your selector would work based on the code you wrote would look for an element with class="excelGridCell" and then a nested element with a class="excelGridCell".
Also, I usually only use mixins for something that needs a parameter (potentially with a default value).
For this use case, you may want to just use @extend with some inheritance.
See section "Extend/Inheritance"
in https://sass-lang.com/guide
however this might be a bit of a religious war https://csswizardry.com/2014/11/when-to-use-extend-when-to-use-a-mixin/
You can import it like this;
@import "../../_variables";
@import "../_mixins";
@import "_main";
@import "_login";
@import "_exception";
@import "_utils";
@import "_dashboard";
@import "_landing";
According to your directories and it will do what you want.
You can use @use rule for it. This rule loads another Sass file as a module, which means you can refer to its variables, mixins, and functions in your Sass file with a namespace based on the filename. Using a file will also include the CSS it generates in your compiled output!
// _base.scss
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}
see how to using @use 'base'; in the styles.scss file
// styles.scss
@use 'base';
.inverse {
background-color: base.$primary-color;
color: white;
}
you don't need to include the file extension.
We all know that Angular has component-specific SCSS file for styling which is really a good thing. We mostly write our common/global styles in styles.scss file or any other file which is imported into styles.scss file. Suppose we have variables.scss and mixins.scss file. These files contain variables and mixins. whenever we need to use them we can import them into styles.scss file to use them in that file. But, if we need those variables and mixin in our specific components we need to import them again into our components.
-
Doesn't it have any performance issues? like redundant variables and mixins in components as well.
-
Isn't it like building/bundling variables and mixins multiple times for each component we have imported into?
-
isn't this increasing the build/bundle size for each component and global component as well?
My question is what is the best way to access variables and mixins globally or locally (by importing in component) without having any performance issues and bundle size issues?