How to use global variables in CSS-Modules?

前端 未结 4 2153
猫巷女王i
猫巷女王i 2021-02-13 13:24

I\'m busy learning React with CSS-Modules and I don\'t quite understand how one would store variables? For example, in Sass you\'re able to do this:

// _variable         


        
4条回答
  •  不思量自难忘°
    2021-02-13 13:49

    One way could be to use dependencies. For example,

    // variables.css
    .primaryColor {
      color: #f1f1f1
    }
    
    // heading.css
    .heading {
      composes: primaryColor from "./variables.css"
    }
    

    See more detailed information here: https://github.com/css-modules/css-modules#dependencies

    If you're using webpack there are more examples here: https://github.com/webpack/css-loader#composing-css-classes

    Also if you are using webpack you can still use Sass with CSS modules.

提交回复
热议问题