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

Using PostCSS and composing a class from a different file #137

Closed
ericmatthys opened this issue Sep 13, 2015 · 7 comments
Closed

Using PostCSS and composing a class from a different file #137

ericmatthys opened this issue Sep 13, 2015 · 7 comments

Comments

@ericmatthys
Copy link

I am using PostCSS with the simple vars plugin, as an example. I have the loaders set up like:

loader: 'style!css?modules!postcss'
.link1 {
  composes: link2 from './Link2.css';
  color: $firstLinkColor;
}
.link2 {
  color: $secondLinkColor;
}

In that example, link2 won't be run through PostCSS so the variable won't be replaced, but the variable in link1 will be replaced. If I remove the composes, both link1 and link2 are run through PostCSS and both variables are correctly replaced.

@ericmatthys
Copy link
Author

I found #131

composes: link2 from 'postcss!./Link2.css'; fixes the issue.

@sokra
Copy link
Member

sokra commented Sep 24, 2015

That's not the correct way.

See https://github.com/webpack/css-loader#importing-and-chained-loaders

You need to use style-loader!css-loader?importLoaders=1&modules!postcss.

@ericmatthys
Copy link
Author

Thanks for the tip. I missed that in the docs.

@josephfinlayson
Copy link

@ericmatthys close the issue

@eseQ
Copy link

eseQ commented Aug 1, 2017

For webpack v2:

{
  loader: 'css-loader',
  options: {
    importLoaders: 1 // 0 => no loaders (default); 1 => postcss-loader; 2 => postcss-loader, sass-loader
  }
}

@MatteoGabriele
Copy link

MatteoGabriele commented Feb 26, 2019

this is actually not working for me. Only works passing composes: foo from '~postcss!filename' but I don't want to write that every time and also I read that is not the correct way.

my webpack configuration has a importsLoaders with 1 (which is postcss-loader right after css-loader) but still doesn't work: every file requested from within css-modules composes method are not passing via the postcss-loader.

working with Vuejs with the following setup:

  • webpack 4.29.5
  • css-loader 2.1.0
  • postcss-loader 3.0.0

thanks anyone for help

cheers

@privatenumber
Copy link

This thread is outdated, but for anyone still searching...

Setting importsLoaders: 2 despite only postcss-loader following worked for me. Probably because the vue-loader plugin interferes with the loader configuration.

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

6 participants