-
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
feat(gatsby-plugin-less): add support for overriding the default options of css-loader
#9237
Conversation
css-loader
css-loader
Some docs updated in README of the package would be great |
Code itself looks good to me! :) |
@@ -22,7 +22,7 @@ exports.onCreateWebpackConfig = ( | |||
? [loaders.null()] | |||
: [ | |||
loaders.miniCssExtract(), | |||
loaders.css({ importLoaders: 2 }), | |||
loaders.css({ ...cssLoaderOptions, importLoaders: 2 }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pieh I was gonna update the docs, but I noticed that the feature request was made for css-loader
and as I understand, you can chain css-loader
with less-loader
. I haven't looked into this much, but I am curious as to how this works.
I feel like if I understand this it'll help me update the docs appropriately. Thanks for understanding 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way the webpack loaders works is that you can chain them together.
Important thing to know is that loaders run from bottom up - so here:
- we run less loader which will convert less to css
- next we run postcss which will apply some transformations on css
- next up we run css loader which will do couple of things:
- it will handle
@import
andurl
inside css so files referenced by those functions/directives are handled by webpack and bundled in our output - if we are using css modules (kind of "less modules" here ;) ) - it will extract class names so you can use them in your js ( see https://github.com/css-modules/css-modules )
- it will handle
In the issue, example that was presented was overriding camelCase
option, and this option tell css-loader
how to handle css class names with dashes:
.with-dash {
color: red;
}
import classNames from "./styles.module.css"
// styles will always be an object that maps class name in css to generated css module class name (so you can use same class name in multiple css modules, because generated classname will prevent collisions)
// depending on `camelCase` option it can be one of the following (just don't remember which setting produce what output):
classNames = {
"with-dash": "some-weird-name-with-hashes"
}
classNames = {
withDash: "some-weird-name-with-hashes"
}
classNames = {
withDash: "some-weird-name-with-hashes",
"with-dash": "some-weird-name-with-hashes",
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holy! That's an in-depth explanation. Still reading it, but just wanted to say I really appreciate it! 🤯
Thanks for being patient @pieh. I think it's okay to merge now 😅sorry for all the trouble! Thanks 💖 |
Don't worry about it - it's all good :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yeskunall!
v2 changed how dashes/hyphens in class names handled by css modules were treated: #5458. This was burdensome as it required changing all `className`s that utilized dashes. This allows overriding that change, almost entirely by copying prior art from @yeskunall & @pieh (#9237).
…ons of `css-loader` (gatsbyjs#9237) Yay! 💖 <hr /> Closes gatsbyjs#9142.
v2 changed how dashes/hyphens in class names handled by css modules were treated: gatsbyjs#5458. This was burdensome as it required changing all `className`s that utilized dashes. This allows overriding that change, almost entirely by copying prior art from @yeskunall & @pieh (gatsbyjs#9237).
…ons of `css-loader` (gatsbyjs#9237) Yay! 💖 <hr /> Closes gatsbyjs#9142.
v2 changed how dashes/hyphens in class names handled by css modules were treated: gatsbyjs#5458. This was burdensome as it required changing all `className`s that utilized dashes. This allows overriding that change, almost entirely by copying prior art from @yeskunall & @pieh (gatsbyjs#9237).
Yay! 💖
Closes #9142.