Created
January 18, 2020 00:02
-
-
Save benmvp/e2ec9cf644320e2ec090f5c78f795cf8 to your computer and use it in GitHub Desktop.
Trying to figure out how to programmatically generate CSS class names using SASS + CSS Modules + babel-react-css-modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$colors: ("white": $white, "yellow": $yellow, "green": $green, "blue": $blue); | |
@each $name, $color in $colors { | |
// this programmatically generates 4 class namaes in the resultant css. | |
// but when Babel parses the module to pull out the class names, it just | |
// gets "bg-color-#${name}" since postcss-scss doesn't compile the SCSS | |
// (https://github.com/postcss/postcss-scss) when used with babel-react-css-modules | |
// (https://github.com/gajus/babel-plugin-react-css-modules#configurate-syntax-loaders) | |
.bg-color-#{$name} { | |
background-color: #{$color}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment