question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include import statements in all SCSS files.

See original GitHub issue

Shouldn’t each SCSS file stand on its own? E.g. if you look at _variables.scss, it references things in _functions.scss, etc. I believe these local imports should be at the top of the file otherwise the consumer needs to import all of the referenced SCSS files in the proper order.

If I am consuming some Bootstrap SCSS, and I need to access the variable $spacer, I would write my SCSS as follows:

@import "~bootstrap/_variables";

.my-class {
  margin-top: $spacer * 2;
}

But this will fail to compile with the message:

argument $color of darken($color, $amount) must be a color

But I’m not doing anything with color here. This is because of the line $link-hover-color: darken($link-color, 15%) !default; in _variables.scss – that line references $link-color which in turn references the theme-color function in _functions.scss.

In order to get my SCSS to compile, I need to dig into _variables.scss and determine which files it needs to import, and then do the same task again for each of those files, and add them all as imports to my SCSS:

@import '~bootstrap/_functions';
@import '~bootstrap/_mixins';
@import '~bootstrap/_variables';

.my-class {
  margin-top: $spacer * 2;
}

IMO, _variables.scss should look like this at the top…

@import '_functions';
@import '_mixins';

…and all of the other SCSS files should import what they need as well. In the end, I should be able to pick any single SCSS file and compile it on its own.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
GauthierPLMcommented, Nov 27, 2019

Now that the module system has been released, is there any plan to support it so we can use @use and @forward?

Is there any known fork that make use of them?

5reactions
voltaekcommented, May 2, 2019

This issue sounds like it may be best solved by the upcoming module system currently being implemented in SASS, which adds @use and @forward, and will eventually replace @import completely.

For more info, see their initial blog post about it (which uses many examples from Bootstrap’s source), and also their accepted feature proposal in their spec repo.

Note that this would not be an immediate solution, as their current timeline puts the new module system not landing until October 2019, and it would likely be best to not require the newest SASS version in order to build Bootstrap right away - though their plan seems to be for it to land in both Dart Sass and LibSass at the same time, which will help with adoption.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass: @import
Sass extends CSS's @import rule with the ability to import Sass and CSS stylesheets, providing access to mixins, functions, and variables and combining ......
Read more >
Sass - Importing files and partials - TutorialsTeacher
Learn how to import files and use partials in this chapter.
Read more >
Sass @import and Partials - W3Schools
By default, Sass transpiles all the .scss files directly. However, when you want to import a file, you do not need the file...
Read more >
Is it possible to import a whole directory in sass using @import?
Not the answer but useful: SASS can import multiple files in one import, like @import 'partials/header', 'partials/viewport', 'partials/footer'; ...
Read more >
@use and @import rules in SCSS - Liquid Light
To use your _button.scss members in another element add your @use rule to the top of your file. You will need to refer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found