0
0
SASSmarkup~8 mins

@forward directive for re-exporting in SASS - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - @forward directive for re-exporting
[Read @forward statement] -> [Locate target Sass file] -> [Import target file's symbols] -> [Re-export symbols] -> [Make symbols available to importing files]
The browser processes the @forward directive by reading it, locating the referenced Sass file, importing its variables, mixins, and functions, then re-exporting them so other Sass files can use them indirectly.
Render Steps - 2 Steps
Code Added:@forward "colors";
Before
[No variables or mixins available]
.button {
  color: undefined;
}
After
[Variables from colors available]
.button {
  color: $primary-color;
}
The @forward directive imports and re-exports variables from the 'colors' file, making $primary-color accessible.
🔧 Browser Action:Resolves and loads the 'colors' Sass file, adds its symbols to the current module's exports.
Code Sample
This Sass code re-exports variables from the 'colors' file, allowing the button to use $primary-color defined there.
SASS
@forward "colors";

.button {
  color: $primary-color;
}
Render Quiz - 3 Questions
Test your understanding
After applying step 1, what happens to the availability of variables from the 'colors' file?
AThey become available for re-export but not for local use.
BThey become available for local use only.
CThey are ignored and not available anywhere.
DThey are imported and immediately compiled to CSS.
Common Confusions - 2 Topics
Why can't I access variables from a file I only @forwarded?
The @forward directive re-exports symbols but does not import them locally. To use variables inside the forwarding file, you must also @use the target file.
💡 Use @use to access symbols locally; @forward only re-exports them for others.
Why does @forward cause duplicate CSS if I also @use the same file?
If you @use a file that is also @forwarded, the CSS from that file can be included twice. Use @forward in a central file and only @use that central file to avoid duplication.
💡 Centralize @forward in one file and @use only that file.
Property Reference
DirectivePurposeEffectCommon Use
@forwardRe-export symbols from another Sass fileMakes variables, mixins, functions available to importing filesOrganize and share Sass modules
@useImport symbols from another Sass fileImports symbols for local use onlyUse variables and mixins from other files
@importLegacy import of Sass or CSS filesIncludes file content directlyOlder Sass projects, now discouraged
Concept Snapshot
@forward re-exports Sass symbols from another file. It does not import symbols locally. Use @use to access symbols inside the file. Helps organize and share variables, mixins, functions. Avoid duplicate CSS by centralizing @forward usage.