Skip to content

CSS modules not works with PostCSS (Webpack 2) #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
azat-io opened this issue Nov 2, 2016 · 8 comments
Closed

CSS modules not works with PostCSS (Webpack 2) #129

azat-io opened this issue Nov 2, 2016 · 8 comments

Comments

@azat-io
Copy link

azat-io commented Nov 2, 2016

It's strange and looks like a bug 🐛

I'm using Webpack v.2.1.0-beta.25

If I add CSS modules to css-loader after postcss-loader the same class names which imports from different .jsx files will have the same hash.

use: [
    'style-loader',
    {
        loader: 'css-loader',
        options: {
            importLoaders: 1,
            modules: true,
            localIdentName: '[local]--[hash:base64:5]',
        },
    },
    'postcss-loader',
],

If I remove postcss-loader and settings for PostCSS all will works good.

This is not plugin problem.

Look here please: https://github.com/azat-io/webpack2-css-modules-demo

At this repo you can see three different components which contains .title class name. If you try to build app you can see that all of this classes will have the same hash.

After then just comment postcss-loader and settings for new webpack.LoaderOptionsPlugin and all will works good.

Previous issue

@ai
Copy link
Contributor

ai commented Nov 2, 2016

@azat-io Could you try PostCSS common config?

@azat-io
Copy link
Author

azat-io commented Nov 3, 2016

@ai Yes. All works good if I put list of plugins to .postcssrc file 😃

@ai
Copy link
Contributor

ai commented Nov 3, 2016

Seems like we have a mystery issue in webpack 2.

I have no idea how to fix it and just will force a common config.

@ai ai closed this as completed Nov 3, 2016
@azat-io
Copy link
Author

azat-io commented Nov 3, 2016

Okay 😞

@ai
Copy link
Contributor

ai commented Nov 3, 2016

If you worry about too many config files, just put PostCSS plugins in package.json.

Or help me with debugging 😆

@ai
Copy link
Contributor

ai commented Nov 3, 2016

Also you could try postcss-modules'

@ghost
Copy link

ghost commented Jan 30, 2017

this work for me. hope it is helpful

@pirelenito
Copy link

This worked for me webpack-contrib/css-loader#413 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants