Export SASS -> JS

Is it possible to export SASS variables to be accessed within JS, without libraries such as sass-to-js?

Nope, because they don’t exist in the CSS. The values of the sass variables are just swapped in when the sass is compiled to CSS, it’s just a dead basic string replacement.

If you use CSS custom properties (ie CSS variables) instead, then yes, absolutely, but the trade-off is that they’re a bit more verbose to write.

Sass was created a long time before CSS variables were a thing, and unfortunately the two things are quite different with respect to how they work, and sass authors couldn’t just make sass variables be CSS variables once the latter were a thing.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.