Performance: Namespace control with @use as
This affects CSS bundle size and style calculation by controlling how styles and variables are imported and referenced.
@use 'colors' as c; .button { color: c.$primary-color; }
@import 'colors'; @import 'colors'; .button { color: $primary-color; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| @import multiple times | N/A | N/A | Higher paint cost due to larger CSS | [X] Bad |
| @use with namespace alias | N/A | N/A | Lower paint cost due to smaller CSS | [OK] Good |
@use 'colors' as c; statement do in Sass?@use rule imports a Sass file and creates a namespace for its variables and mixins.as c partas c renames the namespace from the default (usually the filename) to c.as renames namespace [OK]@use 'file' as alias; renames namespace [OK]buttons.scss with namespace btn?as before the alias.as correctly. Options A, C, and D miss quotes or the as keyword.as keyword = correct syntax [OK]@use 'theme/colors' as c; and the file colors.scss contains $primary: #0055ff;, what is the correct way to use $primary in your styles?@use 'file' as alias;, variables must be accessed with alias.variable.c, the variable $primary is accessed as c.$primary.@use 'utils' as u;
.button { color: $main-color; }@use 'utils' as u; statement correctly imports the file with namespace u.@use 'utils' as u; creates a namespace u, variables inside must be accessed as u.$main-color. Using $main-color alone causes an error.colors.scss with $primary: #333; and buttons.scss with $primary: #555;. How do you import both files in main.scss using @use with aliases c and b to avoid naming conflicts and use both $primary variables?c for colors and b for buttons.b.$primary for button color and c.$primary for background color to distinguish them.Pass the test and this pattern moves unknown