Skip to content
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

postcss-loader doesn’t process CSS Modules composition target #40

Closed
iamakulov opened this issue Dec 23, 2015 · 9 comments
Closed

postcss-loader doesn’t process CSS Modules composition target #40

iamakulov opened this issue Dec 23, 2015 · 9 comments

Comments

@iamakulov
Copy link
Contributor

CSS Modules have a class composition feature which acts similarly to LESS’ :extend() rule. It is enabled by the composes property. The problem is that the class referenced by this property is not processed by postcss-loader.

Example:

/* a.css */
.a {
  display: flex;
}

/* b.css */
.b {
  composes: a from "./a.css";
  user-select: none;
}
/* Webpack config */
module.exports = {
  module: {
    loaders: [
      {
        test: /\.css$/,
        loaders: ['style-loader', 'css-loader?modules&localIdentName=[name]--[local]--[hash:base64:5]', 'postcss-loader']
      }
    ]
  },
  postcss: function () {
    return [autoprefixer({ browsers: ['last 2 versions'] })];
  }
};

With autoprefixer added, the code is compiled to the following:

/* b.css */
.b {
  display: flex;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

As you see, the user-select property is processed and prefixed, whereas display: flex is not.

@ai
Copy link
Contributor

ai commented Dec 23, 2015

You should use css-loader before postcss-loader.

@ai ai closed this as completed Dec 23, 2015
@MoOx
Copy link
Contributor

MoOx commented Dec 23, 2015

@ai It's not possible.
postcss-loader execute the postcss transformation before css-modules produce the css to javascript code. That's probably an discussion that should be done in the css-loader repo. I asked @sokra to make the postcss instance of css modules public so we can plug and transform at the same moment (which might helps in the kind of situation) but we refused :/

@iamakulov
Copy link
Contributor Author

+1, tried it before submitting the issue.

@MoOx, do you know if there is a way to fix the issue without changes from the css-loader side?

@MoOx
Copy link
Contributor

MoOx commented Dec 23, 2015

With my knowledge, there isn't. css-loader does things in a different context... That's sucks for css-modules, like a lot.

@iamakulov
Copy link
Contributor Author

Found the solution: webpack-contrib/css-loader#137.

@ai
Copy link
Contributor

ai commented Dec 23, 2015

Also you can use postcss-modules. I think CSS→JSON magic is not really good.
https://github.com/outpunk/postcss-modules

@ai
Copy link
Contributor

ai commented Dec 23, 2015

@iamakulov maybe we should add this info to docs? Can you send a PR?

@iamakulov
Copy link
Contributor Author

Yep, sure, today or tomorrow.

@ovaldi
Copy link

ovaldi commented Aug 16, 2017

Good job!

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

4 participants