My .scss styles are getting jumbled up by Webpack

As I work with webpack, npm, and react.js, my style.scss stylesheet manages the styles of my project. However, I have been struggling to properly use classes and ids with it. The issue became clear when I noticed the transformation in my style.scss sheet:

/* List items when hovered. */
ul li.hovered{
    background-color: #F8F8F8;
    color: #7B8585;
}

turns into:

/* List items when hovered. */
ul li.style__hovered___j0Fpj {
  background-color: #F8F8F8;
  color: #7B8585; }

after being combined in the style.css file by webpack. This explains why trying to manually set a class like $('#id').toggle("hovered") doesn't work, but

$('#id').toggle("style__hovered___j0Fpj")
does. Despite this odd string persisting through page refreshes, I wonder why webpack mangles class names like this. Is there a way to prevent this behavior or is it intended?

Below is my webpack configuration:

var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'index.js',
    publicPath: '/static/'
  },
  resolve: {
    extensions: ['', '.jsx', '.scss', '.js', '.json'],
    modulesDirectories: [
      'node_modules',
      path.resolve(__dirname, './node_modules')
    ]
  },
  node: {
    console: true,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new ExtractTextPlugin('style.css')
  ],
  module: {
    noParse: /node_modules\/json-schema\/lib\/validate\.js/,
    loaders: [
      {
        test: /\.js$/,
        loaders: ['react-hot', 'babel'],
        include: path.join(__dirname, 'src')
      },
      { test: /\.png$/, loader: "url-loader?limit=100000" },
      { test: /\.jpg$/, loader: "file-loader" },
      {
        test: /(\.scss|\.css)$/,
        loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass?sourceMap!toolbox')
      },
      { test: /\.json$/, loader: "json-loader" }
    ]
  },
  postcss: [autoprefixer]
};

Answer №1

The webpack configuration for Css modules is responsible for transforming your class names dynamically. This module adds a lot of functionality, but it's important to familiarize yourself with the documentation in order to use it effectively. You can find more information here: https://github.com/css-modules/css-modules. If you're not using it correctly, consider removing it from your setup.

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

Incorporated asynchronous functionality, struggling to integrate it into the code

Previously, I used to utilize the following code for handling state: //get state MyClass.prototype.getState = function(key) { var value; switch(this._options.type){ case "cookie": value = $.cookie(key); ...

Creating a scrolling list group in a single column that moves in sync with another longer column

When working with two columns in Bootstrap, such as col-4 and col-8, how can you ensure that a list-group stays fixed within its column and vertically aligned even when the content in the other column is scrolled down? Dealing with this responsively can b ...

Is it possible to use a component created in the newest version of Angular in apps developed with older versions of Angular?

I am interested in developing a component using the most recent version of Angular. However, my intention is to use this component in two distinct Angular applications - one created with Angular 6 and another with Angular 10. Is it feasible to achieve this ...

"Store JSON data into a variable by formatting it through an AJAX POST request

If I want to make a controller call like this: name.php?data={"user":"test","pass":"test"} To retrieve the necessary information using .ajax, I need assistance in configuring the variable to be sent in that specific format. I previously used the follow ...

Steps to include a title next to a progress bar:

Is there a way to achieve something like this? https://i.sstatic.net/dhO2f.jpg I attempted to use bootstrap but I ran into an issue where the title was slightly misaligned below the progress bar. Can someone offer assistance with this matter? Apologies i ...

Checking the service callback function in an AngularJS controller test

I have a Controller that utilizes a service with a callback function upon success. Controller Function itemCtrl.save = function () { ItemService.save({ username: SessionService.getUsername() }, itemCtrl.item, function (res) { $scope.$emit(&ap ...

Guidelines for converting a number into an array of strings using JavaScript

Task: Write a function that takes a number and returns an array of strings, each element being the number cut off at each digit. Examples: For 420, the function should return ["4", "42", "420"]; For 2017, the function should return ["2", "20", "201", "2017 ...

Having Difficulty Configuring Async Request Outcome

I'm struggling to access the outcome of an asynchronous request made to an rss feed. After reading a post on How do I return the response from an asynchronous call?, which recommended using Promises, I tried implementing one. However, even though the ...

Guide on generating a video thumbnail using JavaScript Application

Searching for a way to easily create a thumbnail from a video for uploading alongside the video itself to a server? I've been looking for JavaScript libraries to simplify the process without much luck. The scenario involves the user selecting a video ...

Attempting to implement a functionality that will allow users to easily delete records from the database

I've taken on a school project where I am tasked with creating a login/registration form. Additionally, I need to develop functionality that allows users to register, login, view records, and delete records from the database using a dropdown menu and ...

Tips for Limiting Student Attendance Logging in MERN: Ensure that students can only log their attendance once per day. If a student tries to log attendance a second time, an error message should be displayed

Currently, I am developing a Student Attendance System using MERN Stack. As part of this project, I am creating an API in Node.js/Express.js to handle the attendance marking process for users. One challenge that I am facing is figuring out how to ensure th ...

Using Webpack to directly embed image paths in your code

I am working on a project that uses webpack and vue.js. I encountered an issue when trying to add an image to the vue template using src '/images/imageName.png', which resulted in a 404 error. How can I adjust the configuration to recognize absol ...

Enhance the angular 2 dependencies within the angular2-cli project

After experimenting with Angular 2 and following the guide on their website, I attempted to switch to Angular 2 CLI. However, the Angular 2 CLI project does not have the latest dependencies, resulting in errors from the compiler related to certain commands ...

Developing a trivia game using HTML and JavaScript

I'm in need of some serious assistance with creating a quiz using HTML. My goal is to have a web page where users can visit, take a quiz, and have their responses stored. Unfortunately, I don't have the knowledge or skills required to do this on ...

Unable to integrate the datepicker module into angular.js framework

I encountered an issue when trying to integrate the angular-datepicker module using angular.js. Error: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.6/$injector/modulerr?p0=Channabasavashwara&…0at%20d%20(http%3A%2F%2Fodite ...

Guide to altering the properties of child divs using JavaScript within the parent div

#va{ color:yellow; } #v{ color:pink; } <div id = "va"> <div id ="v">my name is </div> <div>khan</div> </div> After trying to use document.getelementbyid("va").style.color="yellow";, I found ...

What is the best way to display service data as soon as it is received using $http, without relying on angular.copy?

My challenge is with a service that is supposed to store specific data loaded from a JSON file and display it on the webpage immediately upon receiving. I attempted to set a $scope variable equal to the data in the service, but the data did not show up rig ...

Charting Add-Ons for jQuery

Looking for suggestions on user-friendly graph drawing plugins compatible with jQuery. Currently developing a web application that will retrieve data from a remote database and present it through visual graphs... Explored jgcharts (the jQuery Google Chart ...

How can I position a Font Awesome icon in the center of an image with Bootstrap 3?

I'm attempting to center a font-awesome icon on top of an image within bootstrap 3. Below is the image code enclosed in a div: <div id="quickVideo"> <a data-fancybox href="https://player.vimeo.com/video/153113362?autoplay=1&color=54 ...

What is the best way to set the width of an inner element as a percentage of the Body's width?

Applying a percentage width to any inner element of a page will typically result in that element taking a percentage of its parent container's width. Is there a way to specify the width of an inner element as a percentage of the overall Body width, r ...