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-postcss): added css-loader options #10861

Merged
merged 9 commits into from
Mar 15, 2019
Merged

feat(gatsby-plugin-postcss): added css-loader options #10861

merged 9 commits into from
Mar 15, 2019

Conversation

magicspon
Copy link
Contributor

Description

This commit allows users to define some css-loader options, such as localIdentName

{
	resolve: `gatsby-plugin-postcss`,
	options: {
		postCssPlugins: plugins,
		cssOptions: {
			localIdentName: 'mod-[hash:base64:8]'
		}
	}
}

cssOptions is the new bit.

Related Issues

Some of my class names were getting stupidly long!

Copy link
Contributor

@calcsam calcsam left a comment

Choose a reason for hiding this comment

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

This looks like it should work, but

@calcsam
Copy link
Contributor

calcsam commented Jan 25, 2019

...should the API be eg "cssLoaderOptions" for clarity?

@magicspon
Copy link
Contributor Author

yup, that makes sense, i've changed it to cssLoaderOptions.

thanks

@KingScooty
Copy link

Does this PR mean i'd be able to set the camelCase option in css loader?!

cssLoaderOptions: {
  camelCase: false
}

Amazing if so. Let's get this in!

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

I've updated the README.md and added cssLoaderOptions to our non-modules rule too.

It's ready to be MERGED! Thank you!

@wardpeet wardpeet changed the title added css-loader options to gatsby-plugin-postcss feat(gatsby-plugin-postcss)l added css-loader options Feb 1, 2019
@pieh
Copy link
Contributor

pieh commented Feb 1, 2019

We also need to update jest snapshots as seems slight order change of options make them fail

@mbifulco
Copy link
Contributor

Hey there - anything I can do to help with this PR? It looks like this would be helpful for a project I'm working on.

My use case:

  • I'm setting up Gatsby and Storybookjs in the same project. Right now, Gatsby and Storybook have both chosen to feed opposing options into the css-loader camelCase option, which means the same styles.module.css file gets compiled down to a camelCase based dictionary in one project, and a skewer-case dictionary in the other:

In other words...

import classes from './Footer.module.css';

console.log('footer classes', classes);

This results in

Camel Case from gatsby:

image

Skewer-case from storybook:

image

This essentially renders storybook and gatsby incompatible for my purposes. I'm hoping this PR would help me address that!

@wardpeet wardpeet changed the title feat(gatsby-plugin-postcss)l added css-loader options feat(gatsby-plugin-postcss): added css-loader options Mar 12, 2019
@wardpeet
Copy link
Contributor

i'll get this one merged tomorrow @mbifulco

@magicspon
Copy link
Contributor Author

heyo... sorry i've not had a chance to take another look at this... let me know if there is anything i can do to help.

cheers

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

Ready to go! Thanks for your patience!

@mbifulco
Copy link
Contributor

I hate to be a pain, but it looks like failing tests may be holding this up. Is that jest missing a snapshot update?

@wardpeet
Copy link
Contributor

sorry fell sick yesterday, updated the snapshots 🤞

@wardpeet wardpeet merged commit 88b3158 into gatsbyjs:master Mar 15, 2019
@mbifulco
Copy link
Contributor

Ah sorry to hear you were under the weather. I hope you're back at full steam now!

Thank you, @wardpeet @magicspon @pieh! 🙏

@mbifulco
Copy link
Contributor

mbifulco commented Mar 18, 2019

Just coming back to say that this absolutely did the trick for me. Thanks, y'all! This is the postcss config I needed:

    {
      resolve: `gatsby-plugin-postcss`,
      options: {
        cssLoaderOptions: {
          camelCase: true,
        },
      },
    },

and this is a screenshot of thegymnasium.com's new footer design running simultaneously in storybook and gatsby develop 👍 Sweet!

image

gatsbybot pushed a commit that referenced this pull request Aug 13, 2019
…#16521)

* fix(gatsby-plugin-postcss): Fix regression introduced by #10861

* add some tests for scenario when cssLoaderOptions is used

* typo fix
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.

6 participants