Performance: @forward directive for re-exporting
This affects CSS build time and bundle size by controlling how styles are combined and re-exported.
@forward 'buttons'; @forward 'forms'; @forward 'layout';
@import 'buttons'; @import 'forms'; @import 'layout';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using multiple @import statements | No direct DOM impact | No direct reflows | Higher paint cost due to larger CSS | [X] Bad |
| Using @forward to re-export styles | No direct DOM impact | No direct reflows | Lower paint cost due to smaller CSS | [OK] Good |
@forward directive in Sass?@forward@forward directive allows one Sass file to share its styles with another file, acting like a re-export.@forward.@forward shares styles = A [OK]_buttons.scss from _index.scss?@forward directive uses the file name without underscore and extension, so @forward "buttons"; is correct.@import, and @use "buttons"; uses @use, both different directives.// _colors.scss
$primary: blue;
// _index.scss
@forward "colors";
// main.scss
@use "index";
.button {
color: index.$primary;
}@forward "colors"; in _index.scss re-exports mixins, functions, and styles from colors, but NOT variables. Variables are never forwarded.index.$primary is undefined because variables aren't forwarded. Compilation fails with an undefined variable error._index.scss:@forward "buttons"; @forward "buttons";
@forward twice for the same file causes a compilation error because Sass forbids forwarding the same module multiple times.// _colors.scss
$primary: blue;
// _buttons.scss
@forward "colors";
// _index.scss
@forward "buttons";
// main.scss
@use "index";
.button-special {
color: index.$primary;
}main.scss fail to compile with an undefined variable error for index.$primary?$primary is defined in _colors.scss. _buttons.scss forwards colors but does not re-forward $primary explicitly to _index.scss._buttons.scss forwards colors, but _index.scss only forwards buttons, $primary is not visible to main.scss via index namespace.$primary is not forwarded from _buttons.scss explicitly -> Option DPass the test and this pattern moves unknown