babel-plugin-react-css-modules icon indicating copy to clipboard operation
babel-plugin-react-css-modules copied to clipboard

README lacks config documentation

Open jeznag opened this issue 8 years ago • 2 comments

Hi, I can't add a StackOverflow question because the tag is too long. image

I'm having problems configuring babel-plugin-react-css-modules with Webpack v2.5 There doesn't seem to be any documentation on how to set it up and the demo given doesn't work with webpack 2.5 (can't provide query inside loaders anymore).

Here's what I have right now in my webpack config:

      {
        test: /\.s?css$/,
        loaders: [
          'style-loader?sourceMap',
          'css-loader?modules&importLoaders=1&localIdentName=' +
            '[path]___[name]__[local]___[hash:base64:5]'
        ]
      },

And in my .babelrc I have:

      "plugins": [
         "react-css-modules"
      ],

(If I leave the babelrc reference out, I don't get any classes added)

The issue I'm facing is that the classes in the stylesheet don't match the classes applied to the element. Presumably because the context is not correct. But I don't know how to specify the context within webpack config.

jeznag avatar Apr 17 '17 09:04 jeznag

I'm guessing I have to use webpack-combine-loaders. Have tried this:

{
            loader: 'babel-loader',
            query: {
              plugins: [
                [
                  'react-css-modules',
                  {
                    context
                  }
                ]
              ]
            }
          }

and get this error:

ERROR in ./src/index.js
Module build failed: ReferenceError: [BABEL] /Users/jeremynagel/dev/energylink-project/basil-prototype-react/src/index.js: Unknown option: base.plugins[]. Check out http://babeljs.io/docs/usage/options/ for more information about options.

A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

jeznag avatar Apr 18 '17 00:04 jeznag

I have the same problem.

anhuiliujun avatar Jun 01 '17 08:06 anhuiliujun