-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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 CSS modules with a global stylesheet #2726
Comments
Oh interesting — how do you import the css files? Not sure how webpack css extraction works exactly. |
Ah, I'd forgotten how I set this up originally! The global stylesheet is imported in The CSS modules (SCSS) are imported into each respective component. Am I right in thinking that during develop all of these are added to the head via the webpack style loader, but that during build they are first compiled into a single css file and this is then inlined into the html? |
Yeah and we are using the extract text plugin. Just seems like it's not respecting the order of imports. |
The order is going to be determined by when you import the global css. It should be done super early, before you import any components in order to make sure its first in the dep tree |
Yes you're right. I thought I'd imported the global styles first, but there was a single component above it. Maybe I can try and blame IntelliJ auto imports :) Thanks! |
Hmm. So it's now working correctly for develop but not for build... Any insights? |
Moving the style import to the top of |
Hi Alex unrelated but Just started using Gatsby and what is the best way to add additional classes from a global stylesheet (Tachyons in my case) to something with a css module on it?
How do you add your global classes to the styles.header as well? |
Hi @jaydickinson, you can use the classnames utility lib for this (and for composing classnames in general with React, especially if they depend on state).
|
Thanks @baseten for the quick response and that worked perfectly! |
The vanilla alternative would be to use template strings in the classNames prop, like so:
|
@baseten How did you do the |
Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help! |
I'm using gatsby-plugin-postcss-sass with both a global stylesheet (for typography, grid layout, etc.) and css modules for components.
It seems that the component css code is output before the global styles, both during develop and build. I'm not sure why this is the case as I would have thought that components would always want to override global styles?
Either way, is it possible to alter this behaviour either by editing gatsby files by hand (as a short term fix) or some sort of option in config so that css module styles override global styles?
The text was updated successfully, but these errors were encountered: