This webpack.config.js file is dedicated to the module section, where loaders are defined for JSX files and CSS.
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
{
test: /\.css$/,
loader:'style-loader!css-loader'
}
]
}
In addition to the configuration in webpack, css-loader and style-loader have been installed as devDependencies as seen in package.json:
"devDependencies": {
"css-loader": "^0.28.10",
"style-loader": "^0.20.3"
}
The challenge arises when trying to apply CSS styles within a React component using className:
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>
);
}
}
Despite defining simple styles in Foodrecipe.css, changes are not reflecting in the UI when applied through className.
To troubleshoot, applying styles via id (#recipeDiv) instead of className showed successful results, indicating correct CSS file import but potential issues with the className attribute usage.
If you have any insights or guidance on resolving this issue, please share your thoughts. Thank you!