Skip to content

CSS Module composes imports aren't added to webpack #286

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
chrislloyd opened this issue Jun 8, 2016 · 5 comments
Closed

CSS Module composes imports aren't added to webpack #286

chrislloyd opened this issue Jun 8, 2016 · 5 comments

Comments

@chrislloyd
Copy link

Say there's a project like this:

/* a.css */
.red { color: red };

/* b.css */
.main { composes: red from './a.css'; }

and a config roughly like:

module: {
  loaders: [
    {
      test: /a\.css$/,
      loader: 'style-loader!css-loader?modules&localIdentName=a--[local]',
    },
    {
      test: /b\.css$/,
      loader: 'style-loader!css-loader?modules&localIdentName=b--[local]',
    },
  ]
}

a.css will be processed by b.css' loader config even though it does't match the file test. This results in the equivalent of:

.b--red { color: red; }
.b--main { };

even though I'd expect the output to look like:

.a--red { color: red; }
.b--main { };

Ideally css-loader should webpack.addDependency for css module source dependencies so they get processed with the same set of loaders as the rest of the config and not jus the root file's loader url.

@Frizi
Copy link

Frizi commented Jun 30, 2016

This is directly connected to #131. Because webpack loaders config is disregarded for dependencies, css preprocessors are also ignored.

@delijah
Copy link

delijah commented Sep 19, 2016

Is there any progress on this? Is there a reason why dependencies are not processed with webpack loaders config? @sokra

@fredericgrati
Copy link

fredericgrati commented Aug 8, 2017

I'm stuck with this issue. Is there any progress on this ?

I have roughly the same webpack config and the same result :

  module: {
    rules: [
      {
        test: /global\.css$/,
        use: extractLocalStyle.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                sourceMap: true,
              },
            },
            { loader: 'postcss-loader' },
          ],
        }),
      },
      {
        test: /\.css$/,
        exclude: [/global/, /node_modules/],
        use: extractLocalStyle.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                importLoaders: 1,
                modules: true,
                sourceMap: true,
                localIdentName: '[name]_[local]_[hash:base64:3]',
              },
            },
            { loader: 'postcss-loader' },
          ],
        }),
      },
  ]
}

a.css

@import "./b.global.css";
    
.specific {
  line-height: 30px;
}

b.css

.global {
    line-height: 20px;
}

file-558a148428a98beb4fa4.css

.button_global_ivy {
    line-height: 20px;
}    
.button_specific_3Oc {
    line-height: 30px;
}

expected

.global {
    line-height: 20px;
}    
.button_specific_3Oc {
    line-height: 30px;
}

@alexander-akait
Copy link
Member

PR welcome!

@alexander-akait
Copy link
Member

Use importLoaders: false for this case, but better avoid this construction and use getLocalIdent function for change ident based on context/request

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

No branches or pull requests

7 participants