How to control Sass Variable with javascript

前端 未结 8 1644
予麋鹿
予麋鹿 2020-12-01 17:47

I have a Sass file which is generating a CSS file. I have used many variables in my sass file for background color, font-size, now I want to control my all variables through

8条回答
  •  余生分开走
    2020-12-01 18:35

    I find sass-extract-loader especially helpful for using with Create-React-App.

    You can use it like:

    _variables.scss

    $theme-colors: (
      "primary": #00695F,
      "info": #00A59B
    );
    

    component.tsx

     const style = require('sass-extract-loader!./_variables.scss');
     const brandInfo = style.global['$theme-colors'].value.primary.value.hex; // '#00695F';
    

提交回复
热议问题