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 Overflow
🌐
Sass
sass-lang.com › documentation › at-rules › import
Sass: @import
When Sass imports a file, that file is evaluated as though its contents appeared directly in place of the @import. Any mixins, functions, and variables from the imported file are made available, and all its CSS is included at the exact point where the @import was written.
🌐
Sass
sass-lang.com › documentation › at-rules › mixin
mixin and @include
Mixins are included into the current context using the @include at-rule, which is written @include <name> or @include <name>(<arguments...>), with the name of the mixin being included. SCSS · Sass · CSS · Playground ·
Discussions

Can't @use mixin, but can @import
I have a top-level file that only has: · 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: More on github.com
🌐 github.com
9
May 6, 2020
Can i use mixins defined in a partial that is imported in the main scss file in another partial?
You have to import the mixins before importing navigation.scss. So the order inside the style file matters. More on reddit.com
🌐 r/webdev
10
1
September 13, 2024
Import and export mixins, functions, extend
I want to expand *.scss, but expansion may not be implemented. This problem was solved using @import, @mixin and @include. Can it be solved with @use? Passing only variables limits the possibilitie... More on github.com
🌐 github.com
4
October 14, 2019
Using @import statements within control directives or mixins
In #1193, I mentioned why it would be a great idea to allow function or mixing definitions within control directives. An alternative solution would be to allow @import statements within control dir... More on github.com
🌐 github.com
11
March 28, 2014
🌐
Sass
sass-lang.com › documentation › at-rules › use
Sass: @use
Configuring modules with @use ... ... the @import rule. But it’s not particularly flexible, and we don’t recommend it for more advanced use-cases. If you find yourself wanting to configure many variables at once, pass maps as configuration, or update the configuration after the module is loaded, consider writing a mixin to set your variables instead and another mixin to inject your styles. ... // _library.scss $-black: #000; ...
🌐
GitHub
github.com › sass › sass › issues › 2858
Can't @use mixin, but can @import · Issue #2858 · sass/sass
May 6, 2020 - 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"); }
Author   dakom
🌐
Reddit
reddit.com › r/webdev › can i use mixins defined in a partial that is imported in the main scss file in another partial?
r/webdev on Reddit: Can i use mixins defined in a partial that is imported in the main scss file in another partial?
September 13, 2024 -

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?

🌐
Bootstrap
getbootstrap.com › docs › 5.0 › customize › sass
Sass · Bootstrap v5.0
Utilize our source Sass files to ... maps, mixins, and more. Whenever possible, avoid modifying Bootstrap’s core files. For Sass, that means creating your own stylesheet that imports Bootstrap so you can modify and extend it. Assuming you’re using a package manager like npm, you’ll have a file structure that looks like this: your-project/ ├── scss │ └── ...
Find elsewhere
🌐
Sass
sass-lang.com › guide
Sass: Sass Basics
You don’t have to write all your Sass in a single file. You can split it up however you want with the @use rule. 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.
🌐
GitHub
github.com › sass › sass › issues › 2754
Import and export mixins, functions, extend · Issue #2754 · sass/sass
October 14, 2019 - I want to expand *.scss, but expansion may not be implemented. This problem was solved using @import, @mixin and @include. Can it be solved with @use? Passing only variables limits the possibilities. // _alpha.scss $primary-color: #333; ...
Author   dmitrach
🌐
GitHub
github.com › sass › sass › issues › 1194
Using @import statements within control directives or mixins · Issue #1194 · sass/sass
March 28, 2014 - @mixin do_magic($option1 : false, $option2 : false) { @if $option1 { @import '_option1'; } @if $option2 { @import '_option2'; } @if $option1 and $option2 { @import '_bothoptions'; } }
Author   jslegers
🌐
Medium
medium.com › geekculture › how-i-use-mixins-in-sass-cc490bdce662
How I Use Mixins in Sass. Sass has helped me add more… | by Sanjar Kairosh | Geek Culture | Medium
March 9, 2021 - For blog-content-dark the argument passed into the mixin had to be set to dark=true , after which the condition in the if statement within the mixin was met. Thus by choosing Sass over regular CSS, more flexibility and functionality could be introduced to my stylesheet. To use the two styles above, I had to import them from a Sass module file and add them to the className property of a react component as follows:
🌐
W3Schools
w3schools.com › sass › sass_mixin_include.asp
Sass @mixin and @include
Sass HOME Sass Intro Sass Installation Sass Variables Sass Nesting Sass @import Sass @mixin Sass @extend
Top answer
1 of 3
16

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

2 of 3
2

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 .......
🌐
Stack Overflow
stackoverflow.com › questions › 70319006 › import-content-of-scss-file-using-mixin
sass - import content of scss file using mixin - Stack Overflow
// media.scss @mixin media($width, $url) { @media (min-width:$width) { @import url($url); } }; @mixin small($url) { @include media(576, $url); }; //main.scss @import '../../styles/media.scss'; @include small('./styles/small.scss'); .menu { height: ...
🌐
TutorialsTeacher
tutorialsteacher.com › sass › sass-mixins
Sass - Mixins
SCSS: Mixin Copy · @mixin float-left ... you can (and usually will) define mixins in a partial. Just @import the file itself before you use the @include directive....
🌐
Reddit
reddit.com › r/angular › how do you work with scss variables and mixins in angular component.scss?
r/angular on Reddit: How do you work with SCSS variables and Mixins in Angular component.scss?
October 13, 2021 -

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.

  1. Doesn't it have any performance issues? like redundant variables and mixins in components as well.

  2. Isn't it like building/bundling variables and mixins multiple times for each component we have imported into?

  3. 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?

🌐
Liquid Light
liquidlight.co.uk › home
@use and @import rules in SCSS - Liquid Light
July 5, 2023 - Fundamentally both rules do the same thing - load members inside another module. The main differences is how they handle members. @import makes everything globally accessible in the target file. This enables an endless chain of imported files where it's difficult to trace where your variables ...
🌐
KoderHQ
koderhq.com › tutorial › sass › mixin
Sass/SCSS Mixins, Functions & @includes Tutorial | KoderHQ
Mixins aren’t globally available and will have to be imported into the file where we are using them with the @use rule.
🌐
Medium
medium.com › @philip.mutua › difference-between-use-and-import-in-scss-1cb6f501e649
Difference Between @use and @import in SCSS | by Philip Mutua | Medium
October 20, 2024 - Naming Collisions: Because everything is global, libraries must prefix variables, functions, and mixins to prevent conflicts with other imported files. Lack of Control: There’s no way to control the visibility of variables, mixins, or functions, which limits encapsulation and modularity. ... // _variables.scss $primary-color: #3498db; // styles.scss @import 'variables'; body { background-color: $primary-color; }
🌐
TutorialsTeacher
tutorialsteacher.com › sass › import-files-and-partials
Sass - Importing files and partials
But with a few exceptions, you can also nest @import statements. You can't use nested imports within mixins (discussed later in next chapter) or inside control statements, but otherwise you can use @import wherever you need it.