SASS: Set variable at compile time

后端 未结 2 944
逝去的感伤
逝去的感伤 2020-12-19 01:46

Is it possible to set a sass variable at compile time? I basically want to do this:


$color: red !default;
div#head {

  background-color: $color;

}<         


        
2条回答
  •  有刺的猬
    2020-12-19 02:05

    An alternate of command line options is to create other files assigning values to variables.

    Assume that your code above is in a file named 'style.scss'. To set $color to "blue", create a file such as:

    $color: blue;
    @import "style";
    

    and name it to 'blue.scss' for example. Then compile it with below.

    sass blue.scss:style.css
    

    When you want to assign another value to the variable, make another file named "green.scss" like:

    $color: green;
    @import "style";
    

    Then compile it with

    sass green.scss:anotherstyle.css
    

    It is bothering somewhat but enables to decide values of variables at compile time.

提交回复
热议问题