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

feat(gatsby-plugin-less): add support for overriding the default options of css-loader #9237

Merged
merged 5 commits into from
Oct 22, 2018
Merged

Conversation

yeskunall
Copy link
Contributor

Yay! 💖


Closes #9142.

@pieh pieh changed the title Add support for overriding the default options of css-loader feat(gatsby-plugin-less): add support for overriding the default options of css-loader Oct 19, 2018
@pieh
Copy link
Contributor

pieh commented Oct 19, 2018

Some docs updated in README of the package would be great

@pieh
Copy link
Contributor

pieh commented Oct 19, 2018

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 }),
Copy link
Contributor Author

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 😅

Copy link
Contributor

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 and url 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 )

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",
}

Copy link
Contributor Author

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! 🤯

@yeskunall
Copy link
Contributor Author

Thanks for being patient @pieh. I think it's okay to merge now 😅sorry for all the trouble!

Thanks 💖

@pieh
Copy link
Contributor

pieh commented Oct 22, 2018

Thanks for being patient @pieh. I think it's okay to merge now 😅sorry for all the trouble!

Don't worry about it - it's all good :)
Now we just need to wait for github to start working correctly again :)

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yeskunall!

@pieh pieh merged commit ba82bc4 into gatsbyjs:master Oct 22, 2018
@yeskunall yeskunall deleted the issue-9142 branch October 23, 2018 02:40
pieh pushed a commit that referenced this pull request Nov 1, 2018
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).
jedrichards pushed a commit to jedrichards/gatsby that referenced this pull request Nov 1, 2018
jedrichards pushed a commit to jedrichards/gatsby that referenced this pull request Nov 1, 2018
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).
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
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).
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

Successfully merging this pull request may close these issues.

2 participants