3

Take the following css...

.MyComponent {

  color: blue;
  .Button {
    color: red;
  }
}

And the following React component...

import React from 'react'
import classes from './MyComponent.scss'

export const MyComponent = props =>
  <div className={classes.MyComponent}>
    <button className={classes.Button}>My Button</button>
  </div>

export default MyComponent

The styles for .Button don't seem to be applied.

I'm using postcss-loader, sass-loader, style-loader and node-sass in my Webpack set-up.

Ewan Valentine
  • 3,741
  • 7
  • 43
  • 68

2 Answers2

0

Webpack is detecting the SASS file and if configured correctly it will put them all inside .css file.

So, let's say for example your webpack.config.js is configured to do it (If not there are many React Starter Kit that will show you how)

Use should use the class names like this:

import React from 'react'
import './MyComponent.scss'

export const MyComponent = props =>
  <div className="MyComponent">
    <button className="Button">My Button</button>
  </div>

export default MyComponent

Assuming Webpack will take care the stylesheets.

Ido
  • 2,034
  • 1
  • 17
  • 16
-2

Webpack novice here. I had the same problem. My webpack.conf.js had this in it.

{
  test: /\.css$/,
  loader: ExtractTextWebpackPlugin.extract('style-loader', 'css-loader')
},
{
  test: /\.scss$/,
  loader: "style!css!sass"
}

I removed the scss bit so it was just

{
  test: /\.css$/,
  loader: ExtractTextWebpackPlugin.extract('style-loader', 'css-loader')
}
daslicious
  • 1,535
  • 10
  • 18