Adding SASS/SCSS to your React/NextJS Application

I'm a UI/UX Designer and Full stack developer based in India. I'm currently a CSE undergrad at Cochin University of Science and Technology.
Search for a command to run...

I'm a UI/UX Designer and Full stack developer based in India. I'm currently a CSE undergrad at Cochin University of Science and Technology.
No comments yet. Be the first to comment.
Implementing the famous Wordle game in CLI

Hey everyone! It's been a while since I have written a blog post, and I'm really sorry for that. Would be getting back to writing a few posts every month. Now to address the obvious reason why I'm writing this post, I'm really excited to share with y...

Setting up project and installing required dependencies for the tutorial

This post talks about my journey on how I got into technical writing and also covers few points from the Bootcamp: Session 1

Head and Script Tag of NextJS, ESLint in NextJS and Deploying a NextJS Application

SASS short for Syntactically Awesome StyleSheet (Yes, as the name suggests, it's really awesome), it is just CSS but better (Basically you can say SASS is CSS on steroids!). It is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets
SASS has few options which aren't offered by CSS. Few of them are
Variables: With SASS, you can save information in variables to be used again later. So itโs possible, for example, to centrally store a colour value under a catchier variable.
** Mathematical functions:** In SASS, you can also use mathematical operations like +, -, *, /, or %. This allows you to influence size specifications.
Functions: Other functions also make it easier to work on the design. These allow you to modify colour values or analyze lists, among other things.
Mixins: Mixins, simply said, are templates. You can either create them yourself or simply integrate them into your own code when using a framework.
There are many more amazing features offered by Sass.
Sass includes two syntax options:
SCSS (Sassy CSS): Using the .scss file extension and is fully adjective with CSS syntax
Indented (simply called โSassโ): using .sass file extension and indentation rather than brackets; it is not fully adjective with CSS syntax, but itโs quicker to write.
Adding it to CRA app and NextJS app is a bit different, I will explain how you can add it to both the applications.
It is a straightforward process, you just have to install the sass package and you are good to go!
// using npm
npm i sass
// using yarn
yarn add sass
React-scripts uses sass-loader v8, which prefers node-sass to sass (which has some syntax not supported by node-sass). So we would be using that package instead
// using npm
npm i node-sass@4.14
// using yarn
yarn add node-sass@4.14
Version 4.14 is preferred over the latest version of node-sass because it would throw an error. Or you could refer the below image and install the node-sass version according to your Node version!

After installing the node-sass/sass package now you just have to rename the .css file extension to sass or scss and change the imports, that's it! You have added the sass/scss to your react application.
I hope this blog post helped you guys.
If you're enjoying my articles, consider supporting me with a coffee โ๏ธ. It really helps me a lot.
Feedback helps to improve my articles. I'd love to hear feedback and thoughts on the article. Looking forward to your views.