gajus / babel-plugin-react-css-modules

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

how to work on create-react-app v2? #237

Closed XOneto9 closed 5 years ago

XOneto9 commented 5 years ago

hi, a few days ago, I post some question about that how to it work because of getting error. So, I try to some attempt about to work, but the problem is that if I set the context, configuration of Webpack and etc... the create-react-app v2 has changed to making hashed style name.

In create-react-app v2, the style module format is add "module" character like as

import s from './App.module.scss'

but this babel-plugin-react-css-modules of hashed name in the babelrc is like as "generateScopedName": "[name]_[local]__[hash:base64:5]", so, the results of product class name is like that

<div class="App-module_App__3RxO-">

including "App-module" as [name] .

so I don't know how to use in the create-react-app v2 if I exclude character of name "module" in the scss name, then the create-react-app has not recognized. how can I do that...??

AlbertLucianto commented 5 years ago

@XOneto9 I think one workaround is to change the webpack config from the ejected app

{
  test: cssModuleRegex,
  use: getStyleLoaders({
    importLoaders: 1,
    sourceMap: isEnvProduction
      ? shouldUseSourceMap
      : isEnvDevelopment,
    modules: true,
-   getLocalIdent: getCSSModuleLocalIdent,
+   localIdentName: '[name]__[local]___[hash:base64:5]',
  }),
},
XOneto9 commented 5 years ago

@AlbertLucianto Hi, Thanks to reply. yes, nothing to way to resolve this problem is your solutions.

thanks.

gajus commented 5 years ago

See:

ghost commented 5 years ago

Hello,

I've tried the above craco configuration together with the default babel-plugin-react-css-modules installation npm install babel-plugin-react-css-modules --save but importing with import styles from './styles.css' and referencing to it with styleName='my-style' doesn't work for me.

Am I missing something?