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

Passing options to gatsby-plugin-styled-components #4743

Closed
ugrupp opened this issue Mar 28, 2018 · 3 comments
Closed

Passing options to gatsby-plugin-styled-components #4743

ugrupp opened this issue Mar 28, 2018 · 3 comments

Comments

@ugrupp
Copy link

ugrupp commented Mar 28, 2018

Description

Hey, isn't it possible to pass styled-components options to the gatsby plugin? I tried specifically to set displayName: true, but nothing happens.

This is from my gatsby-config.js

plugins: [
  ...
  {
    resolve: 'gatsby-plugin-styled-components',
    options: {
      displayName: true,
    }
  }
],

Steps to reproduce

Expected result

Element class names should be prefixed with the component names. As described in https://www.styled-components.com/docs/tooling#better-debugging

Actual result

Element class names are missing, as if displayName was still set to false.

Environment

  • Gatsby version (npm list gatsby): gatsby@1.9.241
  • gatsby-cli version (gatsby --version): 1.1.28
  • gatsby-plugin-styled-components: 2.0.11
  • styled-components: 3.2.3

File contents (if changed):

gatsby-config.js: see above

@ugrupp ugrupp changed the title Pass options to gatsby-plugin-styled-components Passing options to gatsby-plugin-styled-components Mar 28, 2018
@ugrupp
Copy link
Author

ugrupp commented Mar 28, 2018

Solved it myself! Turns out the option should be provided to babel-plugin-styled-components.
So these steps fixed it:

  • npm install --save babel-plugin-styled-components
  • Adding a .babelrc with:
{
  "plugins": [
    ["babel-plugin-styled-components", {
      "displayName": true
    }]
  ]
}

@ugrupp ugrupp closed this as completed Mar 28, 2018
@glennreyes
Copy link
Contributor

As far as I understood the plugin options are being passed to the babel options. I think that's still a bug if setting plugin options doesn't affect anything.

https://www.gatsbyjs.org/packages/gatsby-plugin-styled-components/#options

@DSchau
Copy link
Contributor

DSchau commented May 29, 2019

👋 Glenn!

This works just fine!

Given gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-styled-components',
	  options: {
        displayName: true,
        fileName: false
	  }
    }
  ]
}

we see the expected output

<div class="ImageContainer-kOPzZn cmmuwx">
  <!-- Image markup here -->
</div>

Screen Shot 2019-05-29 at 11 24 04 AM

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

3 participants