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

React: Material UI, Counting All the Rows

How many rows does Material UI in REACT support in its free and paid versions? I have a massive dataset exceeding 400 MB. Is this realistic or too ambitious? ...

Tips for assigning information from a react hook within a function or event

Currently, I am in the process of learning how to create hooks in order to efficiently reuse data that needs to be modified across different components. For my project, I am utilizing Material UI's Tabs and require the use of a custom hook called use ...

What is the purpose of downloading the i18n code to the client when it is only used on the server in Next.js SSG

Our use of moment and i18 for translation is restricted to the server side during HTML generation. However, why is this data being downloaded to the client-side? This unnecessarily consumes bandwidth and increases the "Time to Interactive" metric. Here is ...

Using Bootstrap 4 to create a fixed-top navbar and other sticky-top elements

Check out the reproduction here: https://jsbin.com/lawafu/edit?html,output Could this be a bug, an error, a challenge, or an unattainable concept? Prior to scrolling: After scrolling: What I require: Essentially, I need the sidebar to remain visible a ...

SVG Height remains fixed despite aspect ratio adjustments

Using one SVG image in a div with a width of 50px results in a height of 150px in IE11. The correct dimensions should be 50px x 50px. The width is applied correctly, but the height is not. Any suggestions? .svg-cont{ width:50px } img{ max-width:100% ...

Enhance User Experience with a Responsive Website Dropdown Menu

Currently, I am focused on enhancing the responsiveness of my website and I realized that having a well-designed menu for mobile view is essential. To address this need, I added a button that only appears when the screen size is 480px or lower, which seems ...

Having trouble getting a Jasmine test to pass for a basic Angular2 component

Here is a snippet of my basic component setup: @Component({ selector: 'messages', styleUrls: ['messages.component.scss'], templateUrl: 'messages.component.html', }) export class MessagesComponent implements OnInit ...

What is the best way to crop an image to focus solely on the center portion?

Using Bootstrap 3, how can I display an image cropped in a .col-sm-6 grid column? The image is 720px wide. Typically, with the .img-responsive class, the image will resize proportionally when the display size changes. However, I want to crop the left and ...

Webpack is attempting to include an excessive amount of modules while utilizing knex.js with AWS Amplify

I'm running into build errors with a next.js application on AWS Amplify, even though it builds and runs smoothly on my local machine. The issue seems to be related to webpack trying to include all SQL packages that knex may use. The specific error mes ...

How to make a multiline TextInput automatically scroll to the bottom in a react native app

I am trying to create a TextInput component where the text is visible when the keyboard is on. Android usually does this by default, but for some reason, my multiline TextInput is scrolling down to the bottom of the text just like a single line input (with ...

Utilize the splice function when resizing the window based on specific breakpoints

On a series of div elements, I have implemented some JS/jQuery code that organizes them by wrapping every three elements in a container with the class .each-row. <div class="element"></div> <div class="element"></div> <div class ...

The chai property "matchSnapshot" is not valid

https://i.sstatic.net/4wgqq.png After following the instructions provided at this link, I am now in the process of writing basic Jest tests for my React application that uses the Create-React-App starter kit. I came across a recommendation mentioned here ...

What is the best way to nest a div within a flexbox container?

I am attempting to create a div that is based on percentages, and I want to nest a div inside another. Specifically, I want the center (xyz div) to only take up 90% of the height of the content-div. My goal is for the "content" div to be responsive to 90% ...

Creating a simple layout in React-Native with two text components perfectly centered within a single View component

Struggling with aligning two distinct text elements within their components using react-native and native-base. Unable to center the text both vertically and horizontally within the Text component itself. Segregated colors to visualize the issue. The comp ...

Transformation of a double-row header

Click here to view the design - two-row header image I'm struggling with creating a header design that consists of two rows - the first row includes a centered logo and icons on the right side, while the second row contains the menu. Can someone guid ...

New button attribute incorporated in AJAX response automatically

data-original-text is automatically added in ajax success. Here is my code before: <button type="submit" disabled class="btn btn-primary btn-lg btn-block loader" id="idBtn">Verify</button> $(document).on("sub ...

Issue with Material UI tool tip not closing upon clicking on an element is persistent

Check out this link for a material UI tooltip demo I have been experimenting with the material UI tooltip in the provided link. The tooltip pops up when hovering over the button, but it doesn't disappear when clicking on the button. Is this the defau ...

The size of jVectorMap is displayed too diminutive

Why isn't my jVectorMap adjusting to the new height I've specified for the containing div? It only displays at the default height of 54px. Within a document.ready function in my scripts.js file, I have the following code: $('#team-map-usa& ...

Styling div elements to match the dimensions of table rows in CSS

When it comes to CSS, I wouldn't call myself an expert; My question is: is there a way for a div tag to inherit dimensions from specific table rows based on their class or id? For instance: Imagine we have a table with multiple rows, but we don&apos ...

Making AJAX requests to retrieve data from a JSON database array, then utilizing the CSS visibility property to conceal HTML elements dynamically

As a enthusiastic beginner, I'm facing a challenge that seems to have no easy solution. Can someone please assist me with this: How can I assign all the ids from a JSON database to the variable dotContainer, in order to hide all corresponding HTML id ...