gajus / babel-plugin-react-css-modules

Transforms styleName to className using compile time CSS module resolution.
Other
2.05k stars 162 forks source link

setting attributeNames to "className": "className" will not output any classnames #294

Closed paperdave closed 3 years ago

paperdave commented 3 years ago

I know it's done on purpose to use styleName over className, but i don't want to use any global classes in this project at all, so i'd like to try to use this configuration in .babelrc. however, when the mapping equals itself, it gets cleared or something.

"babel-plugin-react-css-modules", {
  "attributeNames": {
    "className": "className"
  }
}

Component Code

import 'index.module.css'

export default function Test() {
  return <div className='container'>hi</div>
}

Compiled Code

import './pages/index.module.css';
export default function Test() {
  return <div>hi</div>;
}

as a workaround i can name the props differently ("className": "class") and it works fine (this is compiled output of same component)

import './pages/index.module.css';
export default function Test() {
  return <div class="index-module__container___3Jw5r">hi</div>;
}

i'd like this kind of edge case to at least work, even if it's kind of a bad idea to even allow happen.

paperdave commented 3 years ago

i tried to fix it myself and from a basic test case it seems to work but it may not work with the advanced use examples this plugin supports. this can be seen in the pr