Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpacker @ 4.2.2 - CSS Modules empty object issue #2404

Closed
jayjamero opened this issue Dec 18, 2019 · 2 comments
Closed

Webpacker @ 4.2.2 - CSS Modules empty object issue #2404

jayjamero opened this issue Dec 18, 2019 · 2 comments

Comments

@jayjamero
Copy link

jayjamero commented Dec 18, 2019

Hi,

Having some issues with importing scss files (css modules) into webpacker. I have a basic react component doing something like

import React from 'react';
import PropTypes from 'prop-types';
import styles from './styles.scss';

export default class HelloWorld extends React.Component {
  render() {
    console.log("styless ", styles);
    return <h1>Noish</h1>
  }
}

Looking at this bit of code results in

const getStyleRule = (test, modules = false, preprocessors = []) => {
  const use = [
    {
      loader: 'css-loader',
      options: {
        sourceMap: true,
        importLoaders: 2,
        modules: modules ? {
          localIdentName: '[name]__[local]___[hash:base64:5]'
        } : false
      }
    },

an empty style object:
Screen Shot 2019-12-19 at 7 58 27 am

However changing it to

const getStyleRule = (test, modules = false, preprocessors = []) => {
  const use = [
    {
      loader: 'css-loader',
      options: {
        sourceMap: true,
        importLoaders: 2,
        modules
      }
    },

Finally gives me the style object i want

Screen Shot 2019-12-19 at 12 18 24 am

I still need all that magic from localIdentName. So had a look at this issue before: #2197 so my first thing was to bump it to get the updated dependency version of css-loader.

Not sure whats going on here

@gauravtiwari
Copy link
Member

To enable css modules, you need to name file as style.module.scss

@jayjamero
Copy link
Author

Cheers that did it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants