Skip to content

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

@iamakulov

Description

@iamakulov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions