Languages
[Edit]
EN

SCSS / SASS - aliases for namespaces imported with @use

0 points
Created by:
Kevin
797

In this article, we would like to show you how to create aliases for namespaces imported with @use in SCSS / SASS.

Quick solution:

@use 'path/to/scss/file-name' as alias-name;

.element {
    color: alias-name.$variable-name;
}

 

Practical example

In this example, we import $font-size variable from assets/fonts.scss file into style.scss and using as keyword we give the fonts file an alias - commons

Project structure

/src/
 |
 +-- assets/
 |    |
 |    +-- fonts.scss
 |
 +------- style.scss

SCSS files

Example assets/fonts.scss file:

$font-size: 1.5rem;

Example style.scss file:

@use 'assets/fonts' as commons;

body {
	font-size: commons.$font-size;  /*  <--- Usage example   */
}

 

See also

  1. SCSS / SASS - import variable

Alternative titles

  1. SCSS / SASS - alias for file imported with @use rule
  2. SCSS / SASS - alias for namespace imported with @use rule
  3. SCSS / SASS - alias for namespace imported with @use rule
  4. SCSS / SASS - import variable with namespace alias
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join