Sometimes, we want to add SCSS styles to a React project.
In this article, we’ll look at how to add SCSS styles to a React project.
How to add SCSS styles to a React project?
To add SCSS styles to a React project, we can install the sass
package if the React project is created with create-react-app.
To install it, we run:
npm install --save-dev sass
or
yarn add -D sass
Then we import a SCSS file by writing:
import '../scss/styles.scss';
We can rename all *.css
files to *.scss
to convert CSS files to SCSS files.
Conclusion
To add SCSS styles to a React project, we can install the sass
package if the React project is created with create-react-app.
2 replies on “How to add SCSS styles to a React project?”
How would you import SASS partials into components?
This method isn’t applicable. Partials aren’t visible when importing and an error occurs:
Cannot find module ‘../scss/components/_search-form’
Did you follow the steps in https://sass-lang.com/documentation/at-rules/import?