Not too long ago I made a project that used a combination of SASS variables and CSS custom properties. I defined my Sass variables and then used those to create my CSS custom properties. Everything worked great. Now I'm trying to do the exact same thing, using the same code and loaders (Webpack) and it's not working and I can't figure out why.
I have a style.scss
file that looks like this:
$var1: #ff3344;
h1 { color: $var1; }
:root { --color1: $var1; }
When I build my project with Webpack using sass-loader
, css-loader
, and style-loader
I get the following output:
h1 { color: #ff3344; }
:root { --color1: $var1; }
For some reason, the $var1
gets replaced for the h1
but not for the --color1
.
Seeing as I did this before with no issue, I expected sass-loader
may be the cause. But I downgraded sass-loader
to 6.0.7 which was the same version I used in the project that this worked in but I'm still having this issue. Why isn't sass-loader
replacing $var1
when it gets assigned to --color1
?