Question
Exporting SCSS Variables to JS (auto looping variables)
UPDATE: If you plan to implement the
export
solution, you must place it in a separate file to prevent redundant exports in your compiled CSS code. See here.
I recently learned that you can export styles from SCSS into JS like so:
_variables.scss
:export {
some-variable: 'some-value';
}
app.js
import styles from 'core-styles/brand/_variables.scss';
Based on this, my _variables.scss
is formatted like so:
/* Define all colours */
$some-color: #000;
$another-color: #000;
// Export the color palette to make it accessible to JS
:export {
some-color: $some-color;
another-color: $another-color;
}
The issue with the above format is that I have to re-define each of my variables within export
. Therefore, I am interested to know whether there is a way to loop
though each of my variables automatically and export them to JS?