This is the style.css file:
.cake {
color: red;
}
This is index.js:
Fails:
import React from "react";
import ReactDOM from "react-dom";
import './style.css';
function App() {
return (
<div className="cake">Hello!</div>
);
}
ReactDOM.render(<App />, document.querySelector("#root"));
The CSS styling fails to render and the text is just black in browser.
However, this does work:
Succeeds:
import React from "react";
import ReactDOM from "react-dom";
import styles from './style.css';
function App() {
return (
<div className={styles.cake}>Hello!!</div>
);
}
ReactDOM.render(<App />, document.querySelector("#root"));
This is the relevant section of webpack.config.js:
{
test: /\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: true
}
}
]
},
I would like to have the option of using the string literal version, and I'm a bit perplexed that many people online seem to have it available. Is there some webpack config change I can apply? Or am I missing something else here?