Consider the following SCSS:
$color-black: #000000; body { --color: $color-black; }
When it is compiled with node-sass version 4.7.2, it produces following CSS:
body { --color: #000000; }
When I compile the same SCSS with version 4.8.3 or higher, it produces following:
body { --color: $color-black; }
What am I missing? I checked release logs, but could not found anything useful. Also, I wonder if this change is genuine why does it have only minor version change? Should it not be a major release?
Also, what is my alternative? Should I use Interpolation?
To convert the SASS variable to a CSS custom property you put curly brackets around it, and a hash in front. If you've used template literals in JavaScript it's the same thing, just with a # instead of a $ (because we already have $ in the variable name).
We are all gladly using SCSS and benefiting from its features. In addition to that, we didn't want to give up on CSS variables, because they are strong, especially when it comes to changing them in run-time, it can't be achieved using SCSS, SASS, or LESS variables.
A Sass variable must be initialized with a value. To change the value, we simply replace the old value with a new one. A variable that's initialized inside a selector can only be used within that selector's scope. A variable that's initialized outside a selector can be used anywhere in the document.
scss already imports all other scss files of template. So when any SCSS file in the scss folder is updated, it will be compiled to . css files. Now, you can start working with SCSS files.
Just use string interpolation:
$color-black: #000000; body { --color: #{$color-black}; }
Apparently the old behaviour is not intended and violated the language specs of SASS:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With