The Modern @use Module System
The @use rule loads a Sass module and exposes its public members through a namespace. This makes dependencies explicit and helps prevent accidental name collisions.
For example, @use "abstracts/tokens"; loads a module whose variables can be accessed through the tokens namespace. The consuming file can then reference tokens.$brand-color.
Use as to select an alias or as * to remove the namespace. Although as * can shorten names, it can also reintroduce naming collisions and hide dependencies. Explicit namespaces are generally easier to maintain in large projects.
Sass modules are loaded once within the module system, so repeated references to the same module do not behave like repeated textual concatenation of the source file.
// abstracts/_tokens.scss
$brand-color: #5b5bd6;
$spacing-md: 1rem;
// abstracts/_mixins.scss
@mixin flex-center {
display: flex;
align-items: center;
justify-content: center;
}
// main.scss
@use "abstracts/tokens";
@use "abstracts/mixins";
.hero {
padding: tokens.$spacing-md;
background: tokens.$brand-color;
@include mixins.flex-center;
}@use statements belong at the beginning of the consuming stylesheet, before ordinary style rules.How does `@use "abstracts/tokens";` expose a public variable by default?