Solve the problem with SCSS at the component level in NextJS

I've decided to transition my regular React app to Next.js.

In the past, I would simply import SCSS files using:

import from '.componentName.scss'

However, now I need to import them using:

import style from 'componentName.module.scss

This means I have a lot of code to update since this project was already completed. Is there a way to configure Next.js to allow me to import SCSS files as I did before?

Answer №1

If you're looking to customize your webpack config in nextjs, you can check out the link here. This will allow you to create a custom webpack config along with defining rules for styles.

...
rules: [
  {
    test: /\.s?css$/,
    use: [
      'style-loader',
      {
        loader: 'css-loader',
        options: {
          modules: true
        }
      },
      'sass-loader',
    ],
    include: /\.s?css$/
  },
],

By utilizing this method, you can potentially modify how nextjs looks for *.module files and includes them in the css bundle. Just be sure to adapt the code to fit your specific requirements rather than blindly copying it.

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

What is the best way to compare a string with a specific object key in order to retrieve the corresponding value?

I'm looking to achieve a relatively simple task, or at least I think so. My goal is to compare the pathname of a page with key-value pairs in an object. For example: if("pathname" === "key"){return value;} That's all there is to it. But I&apos ...

Using Backbone to Retrieve a JSON File from a Server: Deciding Whether to Include the File Extension ".json" in the URL or URLRoot

Exploring Backbone with exercise by trying to obtain a JSON file from the server using the urlRoot property of the Model. Encountered an error (404) when setting urlRoot: "./js/json/todo", paths with ".json" work but console.log(todoItem.get('descrip ...

Seemingly the Tailwind Styles are failing to take effect in my Next.js Project

While following a Next.js tutorial project, I ran into an issue where my project seemed to be way off. It appeared that the tailwind styles were not being applied for some reason, even after tweaking the 'tailwind.config.js' file without success. ...

What method can I use to ensure that the sidebar stays fixed at a particular div as the user continues to scroll down the

Is there a way to automatically fix the sidebar once the user scrolls down and hits the top of the .Section2? Currently, I have to manually enter a threshold number which can be problematic due to varying positions across browsers and systems. Fiddle htt ...

How can I display an ngx spinner after a delay of 1 second?

I am uncertain about the answer I came across on this platform. intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const time = 900; const spinnerLogic = () => { if (this.isRequestServed ...

Sort the parent by the number present in the child item using jQuery

Is there a way to rearrange a list of items based on a specific number within each item? Consider the following HTML structure that cannot be modified: <ul id="ul-list"> <li> <div class="name">product 1</div> & ...

Error: The React Native code is unable to access the property 'CameraType' because it is undefined

I'm experiencing issues with my app crashing on an Android device when trying to utilize the expo-camera for camera features. Here is a snippet of my JavaScript code: import React, { useState, useEffect, useRef } from 'react'; import { Text, ...

Experiencing a bug in the production build of my application involving Webpack, React, postCSS, and potentially other JavaScript code not injecting correctly

I've encountered an issue with my webpack.prod.config when building my assets, which may also be related to the JS Babel configuration. While I can successfully get it to work in the development build by inline CSS, the problem arises when attempting ...

What are the best ways to stop jQuery events from propagating to ancestor elements?

I have a collection of nested UL's that follow this structure: <ul class="categorySelect" id=""> <li class="selected">Root<span class='catID'>1</span> <ul class="" id=""> <li>First Cat<span ...

Within the callback function, the original state is always displayed

I am working on a stateful functional React component and I am also using sortablejs. const myComponent = () => { const [myData, setMyData] = useState([...some initial array data...]); const testMe = () => console.log(myData) useEffect(() => ...

Selenium RC: Utilizing the CSS :contains pseudo-class for Element Selection

I have a task to verify that the data in a table row matches my expectations for two different tables. Let's look at an example using HTML: <table> <tr> <th>Table 1</th> </tr> <tr> <t ...

Where will the user's input be stored?

Consider the following HTML code: <div class="form-group"> <label class="col-md-3 col-xs-3 col-sm-3 control-label">Phone</label> <div class="col-md-4 col-xs-4 col-sm-4"> <input id="input ...

Utilize jQuery to wrap text within <b> tags and separate them with <br> tags

Upon receiving output in html string format from services, I am presented with the following: "<html>↵<h1>↵Example : ↵<br>Explanation↵</h1>↵<hr>↵<b>key1 : ABCD <br>key2 : 2016-10-18-18-38-29<br> ...

what is the process for creating a dynamic display slide in bxslider?

I am trying to create a flexible length display using bxSlider. Here is the code I have so far. JS var duration = $('ul > li > img').data("bekleme"); $(document).ready(function () { $('.bxslider').bxSlider({ ...

How to detect the Back Button or Forward Button events in a single-page application

Currently, I am developing a single-page application that utilizes ASP.NET MVC, Backbone.js, and JQuery. My task involves capturing the browser's back and forward button events for breadcrumb implementation. I previously attempted to use the hashchan ...

Tips for displaying a list of objects in React

I'm currently developing an application using React, where I have created two components. One of these components is supposed to receive an object from its parent component for rendering. This object consists of multiple elements, one being an array c ...

Is there a way to extract the text that lies between two closed HTML

Looking for a solution using jQuery. <pre><marker id="markerStart"></marker> aaaaa <span style='font-family:monospace;background-color:#a0a0a0;'>bbb</span>bb cc<marker id="markerEnd"></marker>ccc </pr ...

Stylish border radius for Bootstrap progress bars

Here is a snippet of code that I am struggling with: .progress-bar{ border-top-right-radius: 40px !important; border-bottom-right-radius: 40px !important; -webkit-box-shadow: none !important; -moz-box-shadow: none !important; box-sha ...

Troubleshooting issues with JavaScript events in order to effectively implement popovers

I am facing an issue on a webpage that contains a significant amount of JavaScript. The Twitter bootstrap's popover widget is not functioning as expected. Specifically, when I hover over the icon that should trigger the "popover," nothing happens. I h ...

Develop a CakePHP CRUD view using a JavaScript framework

Creating a CRUD view in Cake PHP is simple with the following command: bin/cake bake all users This command builds the users table for CRUD operations. Is there a JavaScript framework that offers similar simplicity? ...