Combining Sass and SCSS in webpack: A step-by-step guide

Just curious about something.

I have some libraries I'm interested in using (for example, font-awesome) that use scss, but I personally prefer working with sass.

How can I set up my project with webpack to accommodate this?

Here's my current setup:

...
rules: [
  ...
  {
    test: /\.(c|sa|sc)ss$/,
    use: [
      'style-loader',
      'css-loader',
      'scss-loader',
      'sass-loader'
    ]
  }
]
...

Appreciate any help you can offer!

Answer №1

To modify your webpack setup for a React app, consider using react-app-rewired. You can refer to my changes in this specific commit

If you prefer directly editing the webpack.config.js file, follow these steps:

npm install style-loader css-loader --save-dev

Then, in your webpack.config.js file, insert the following object into your rules array:

// webpack.config.js
module.exports = {
    ...
    module: {
        rules: [{
            test: /\.scss$/,
            use: [
                "style-loader", // creates style nodes from JS strings
                "css-loader", // translates CSS into CommonJS
                "sass-loader" // compiles Sass to CSS
            ]
        }]
    }
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Make Bootstrap 3 Collapse Panels Stand Out with an Active Class

First of all, here is the fiddle link: http://jsfiddle.net/krish7878/h38jn324 I have a simple question. When a panel is clicked and it expands to show its contents, a class 'active' should be added to 'panel-heading'. I came across a ...

Issues with initializing React code - A beginner's guide to troubleshooting in React development

The div ID specified on line 9 is not being displayed as expected. The output does not include the text placed under the reactDom.render function. It only shows "Hello World from the index" on line 10. What could be causing this issue? I am utilizing t ...

Implement a class attribute to the parent <div> element using React and TypeScript

I'm trying to figure out how to achieve this task. I need to assign a class upon clicking on an element that is not directly in my code, but rather in one of its parent elements. My initial thought was to accomplish this with jQuery using the followi ...

Changing the size of a Material UI card component by clicking and dragging one of its corners

My project involves a collection of Material UI cards organized in a React Beautiful DND list. I have successfully implemented the functionality to move cards from one list to another and reorganize them. Now, I am looking for a way to enable users to resi ...

What is the best way to customize the color of the border and icon in an outlined MaterialUI input field

I'm a newcomer to materialUI and I have a question regarding customizing an outlined input field with an icon. Due to my dark background, I need the icon, border, and text color to be lighter, such as grey. Can someone please advise on the materialUI ...

There was an issue with the NextJS axios request as it returned a status code

I'm currently in the process of developing an application with NextJS and Strapi In my project, I am fetching data from Strapi using Axios within NextJS Next: 14.0.4 Axios: ^1.6.5 Strapi: 4.17.1 Node: 18.17.0 Here is the code snippet: import axios f ...

Struggling with halting a React countdown timer

I'm a beginner with React and I've managed to tweak a countdown timer to suit my needs. The only issue I'm facing is how to make the timer stop when it reaches zero, showing "0:00" as the output. While I won't include the beginning par ...

Using SVG files as properties in React from a data.js file

I have a website where I store my content in a data.js file and pass it to my components using props. Everything is working correctly, except for my .svg files. When I try to display them, they do not appear. However, if I change the extension of the image ...

Create a chronological timeline based on data from a JSON object

Here is a JSON object generated by the backend: { "step1": { "approved": true, "approvalTime": "10-11-2021", "title": "title 1", "description": "description 1" ...

Distribute the elements evenly between two separate divs

Hello everyone! I have a unique challenge that I hope someone can help me with. I have a list of links to various tests, but different sections require these links to be displayed in different ways. One section needs them spread over two columns, while an ...

Differences between Angular 2's ng build and Webpack buildIn this

What is the most effective way to build and deploy my Angular 2 web application? I also need to ensure it can be served as a web bundle resource for my Dropwizard application. Should I stick with ng build to generate my dist folder, or should I custom ...

Having trouble with the mouse trail code on codepen.io

I am currently attempting to integrate this specific CodePen sample into a Hugo template called Somrat Theme. I'm facing challenges in deciding where to place the HTML file; only the 'no cursor' section should go into style.css, and I need ...

Do not use unnecessary variables for storing references in ES6

Despite using react es6, I am still unsure how to refrain from needing to use the variable that for this scenario: const that = this; UploadApi.exec(file).then(data => { that.setState({ loading : false}); }); ...

Unable to generate a React Native application

Here are the instructions to develop a react native app: npm install -g create-react-native-app create-react-native-app my-app cd my-app I successfully completed the first step, but I've been encountering challenges with the second step since yeste ...

Creating basic animations using React and GSAP

I’ve been grappling with this issue for days and struggling to comprehend the various sources of documentation and examples available. I'm really hoping someone can assist me with a specific example that I’m currently working on, which might help ...

Error: Unable to locate module: Could not find '@date-io/date-fns'

I encountered an error while using React Material UI: Module not found: Can't resolve '@date-io/date-fns'. Below are the dependencies listed in my package.json file: "dependencies": { "@date-io/date-fns": "^2.0.0", "@material-ui/co ...

Issues with keyboard accessibility in drop down menus

Looking to improve the keyboard accessibility of my menu bar. Swapped out all instances of :hover with :focus, but unfortunately dropdown menus are still not accessible via keyboard. Does anyone have a solution for this issue? Appreciate any help! ...

Postponing the activation of toggleClass in jQuery until the completion of a slide animation

Having some trouble with the jQuery delay() function. I'm using it to pause a toggleClass action until after a slideUp animation on one of my divs, but it doesn't seem to be working as expected. I want a bar with rounded corners that expands whe ...

Error message: "The contract is not defined in thirdweb-dev/react

I am currently using thirdweb-dev/react library to interact with a smart contract. However, I am encountering an issue where the contract is showing up as undefined in my code along with the following error message: query.ts:444 Error: Could not ...

State in React is not always defined when making a fetch request

Just started using React and encountered an issue while working on my fetch request: I am receiving a formatted response with Axios, but when I try to set the state using the same variable like this: setSelectedStatParams(formattedResponse), it shows up as ...