I'm migrating my CRA to Next and having issues with locally scoped CSS modules.
File Tree
.
├── Headline.js
├── profile.png
└── welcome.module.css
Code
import React from 'react';
import "./welcome.module.css"
function Headline() {
return (
<section className={'headliner-container'}>
<div className={'main-headline'}></div>
</section>
);
}
export default Headline;
I realize I can get this to work by doing import styles from "./welcome.module.css" and referencing via className={styles["classNameHere"]}, but how does that scale for large migration projects? I want to use the CSS I had with minimal modification to my JSX.
Update:
I found out I could add this and disable all the weird opinions Next is throwing into my CSS structure:
module.exports = withCSS({
cssLoaderOptions: {
url: false
}
})
Any opposition to this in my next config?
import "./welcome.module.css", then you're trying to make them global, which is anti-pattern. If you want global CSS, then you shouldn't use themodulename, instead you should use:import "./welcome.css".import "./App.module.css";doesn't even apply styles with the CRA: screenshot. Only when importing and applyingstylesto the element does it work as expected: screenshot. This further points to the fact that, if it's working with.module.cssin your CRA project, then you're just using global classes and not local classes.