React Js
Adding SASS to create-react-app
Installation
In new project, install sass
.
npm i sass
Importing SASS
Rename
App.css
toApp.scss
. Alsoindex.css
toindex.scss
.- In
App.js
andindex.js
fix the import from css to scss. It will result:
import "./index.scss";
Using SASS
- You can edit the scss either in
App.scss
orindex.scss
for example, clear all code in app.scss
, then add the following:
$mainColor: #525763; // assigning the variable
body {
background-color: $mainColor; // consuming the variable
}