This is the module section of my webpack.config.js file
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
// loader: 'babel',
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.css$/,
loader:'style-loader!css-loader'
}
]
}
I have also installed css-loader and style-loader, this is how the package.json file looks -
"devDependencies": {
"css-loader": "^0.28.10",
"style-loader": "^0.20.3"
}
This is my react component where I am trying to implement the CSS -
import React from "react";
import styles from "./Foodrecipe.css";
export default class Foodrecipe extends React.Component {
render() {
return (
<div className={styles.recipe}>
<h1>Healthy Main Dish Recipes</h1>
</div>
);
}
}
The CSS recipe class in Foodrecipe.css file is quite simple, its just -
.recipe{
background-color: yellow;
color: blue;
}
But for some reason, the CSS change is not reflecting in the UI.
One more thing I would like to point out is when I am adding the attribute id to the div and naming it recipeDiv, and declaring the style of the id in the CSS -
#recipeDiv {
background-color: yellow;
color: blue;
}
the changes are reflecting in the UI. So I am pretty sure that the CSS file is getting imported correctly here but there seems to be some issue with className attribute. That's what I think. Can anyone guide me here.