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

Update preset styled-components styled import #207

Merged
merged 1 commit into from
Nov 25, 2020

Conversation

ben-rogerson
Copy link
Owner

@ben-rogerson ben-rogerson commented Nov 24, 2020

This PR updates the styled import when you use { preset: "styled-components" }

// New
import styled from 'styled-components/macro'

// Old
import styled from 'styled-components'

The new import allows you to adjust the styled config in the same place you define the twin config:

// babel-plugin-macros.config.js
module.exports = {
  styledComponents: {
    ssr: true, // Make it behave with SSR
    displayName: true // Improved debugging with react display names in class names
    pure: true, // Enable Dead Code Elimination/Tree Shaking in minifiers like terser
  },
  twin: {
    preset: "styled-components",
    autoCssProp: true,
    debugProp: true,
  },
}

// or in package.json
"babelMacros": {
  "styledComponents": {
    "ssr": true,
    "displayName": true,
    "pure": true
  },
  "twin": {
    "preset": "styled-components",
    "autoCssProp": true,
    "debugProp": true
  }
},

Be sure to check the styled-components docs for the rest of the available options.

Note: The config for this macro is still marked as experimental on the styled-components site but that was based on the linked resource by Kent C. Dodds who has since removed the experimental status.
image
I also checked with Max Stoiber (@mxstbr) to be sure.

@ben-rogerson ben-rogerson merged commit 8818cc3 into master Nov 25, 2020
@ben-rogerson ben-rogerson deleted the feature/preset-styled-components-macro branch November 25, 2020 20:36
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.

1 participant