-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Babel Macros - not working #44
Babel Macros - not working #44
Comments
Hello, yes it is not yet supported. If someone want to work on it, feel free. Else I will probably do it in september. |
I've implemented xstyled in dozens of files in a large app thinking I could use the Babel macro later (for testing) but was surprised it did not work. Sadly, I do not have the time to look into this, because I am working full time, plus have my own Github open-source projects to maintain, with plenty of open issues to address Enjoy your summer holiday! |
@neoziro Shall I work on this? |
@jmlweb yes you can! |
@neoziro My idea is to create Higher Order Functions over the current logic so that you can pass the utils from the styled-components version required (standalone or macro). Something like this:
and then, you use it like this:
or
Does it looks good, or do you have a better implementation idea? |
It should work yes. No I don't have better idea. |
It seems it is not that simple... |
Hi, anyone knows if there is active development on this? |
I took a look, but I don't have any idea about how babel macros work, so I got no success... Feel free to take it :) |
@jmlweb - I know even less 😝 Are we stuck with nobody that knows and can help? |
I am afraid I am the only one involved who knows how to do it. Unfortunately it is not a required feature for me, so I can't give you a date for that feature. |
Hey @neoziro My work around on this was to remove the name from the rollup config of the package And still there is some issues ... = require('styled-components/macro')
// we have
... = require('styled-components') so i used the plugin |
@Wizyma you have to create a specific folder inside the styled-components folder with a |
Any progress in this? This is mega important because I cannot eject my React app and I need automatic classnames for my styled-components for Selenium E2E tests.. Thanks.. This package is deeply integrated in our app in hundred+ files.. |
Looks like the styled-components issue has been fixed in CRA: I would suggest roll your own babel macro if the problem persists. |
Still an issue for v2. |
I know that people would like the macro to work, but for reference in the meantime, here is the formula for using the plugin with xstyled and CRA
@gregberge It would be super cool if the classes generated by |
There are two things preventing the macro from working:
Anyway, all of this needs to become an issue and PR upstream. I'll work on that soon |
If `styled` should come from a wrapper instead of directly from styled-components, this enables users of the macro to customize the import by configuring in `packages.json`: "babelMacros": { "styledComponents": { "importModuleName": "my-styled-components" } } Previously similar functionality landed in babel-plugin-styled-components so users of the plugin could use a wrapper at that level, but it wasn't available to users of the macro. This builds on that work by passing the customized module name through to the plugin. Consequently we also update the dependency to ensure the plugin supports `topLevelImportPaths` See styled-components/babel-plugin-styled-components@325167b Fixes styled-components/xstyled#44
If `styled` should come from a wrapper instead of directly from styled-components, this enables users of the macro to customize the import by configuring in `packages.json`: "babelMacros": { "styledComponents": { "importModuleName": "my-styled-components" } } Previously similar functionality landed in babel-plugin-styled-components so users of the plugin could use a wrapper at that level, but it wasn't available to users of the macro. This builds on that work by passing the customized module name through to the plugin. Consequently we also update the dependency to ensure the plugin supports `topLevelImportPaths` See styled-components/babel-plugin-styled-components@325167b Fixes styled-components/xstyled#44
Pull request is in! Unfortunately it also looks like styled-components upstream is on hiatus, so it could take a while. Also, the PR is against v6 in development, and then it would need to be backported to the If you want to give it a thumbs up, head over to styled-components/styled-components#3422 If you need something earlier, you can
then you can |
If `styled` should come from a wrapper instead of directly from styled-components, this enables users of the macro to customize the import by configuring in `packages.json`: "babelMacros": { "styledComponents": { "importModuleName": "my-styled-components" } } Previously similar functionality landed in babel-plugin-styled-components so users of the plugin could use a wrapper at that level, but it wasn't available to users of the macro. This builds on that work by passing the customized module name through to the plugin. Consequently we also update the dependency to ensure the plugin supports `topLevelImportPaths` See styled-components/babel-plugin-styled-components@325167b Fixes styled-components/xstyled#44
If `styled` should come from a wrapper instead of directly from styled-components, this enables users of the macro to customize the import by configuring in `packages.json`: "babelMacros": { "styledComponents": { "importModuleName": "my-styled-components" } } Previously similar functionality landed in babel-plugin-styled-components so users of the plugin could use a wrapper at that level, but it wasn't available to users of the macro. This builds on that work by passing the customized module name through to the plugin. Consequently we also update the dependency to ensure the plugin supports `topLevelImportPaths` See styled-components/babel-plugin-styled-components@325167b Fixes styled-components/xstyled#44
If `styled` should come from a wrapper instead of directly from styled-components, this enables users of the macro to customize the import by configuring in `packages.json`: "babelMacros": { "styledComponents": { "importModuleName": "my-styled-components" } } Previously similar functionality landed in babel-plugin-styled-components so users of the plugin could use a wrapper at that level, but it wasn't available to users of the macro. This builds on that work by passing the customized module name through to the plugin. Consequently we also update the dependency to ensure the plugin supports `topLevelImportPaths` See styled-components/babel-plugin-styled-components@325167b Fixes styled-components/xstyled#44 Cherry picked from styled-components@83c8b0c
If `styled` should come from a wrapper instead of directly from styled-components, this enables users of the macro to customize the import by configuring in `packages.json`: "babelMacros": { "styledComponents": { "importModuleName": "my-styled-components" } } Previously similar functionality landed in babel-plugin-styled-components so users of the plugin could use a wrapper at that level, but it wasn't available to users of the macro. This builds on that work by passing the customized module name through to the plugin. Consequently we also update the dependency to ensure the plugin supports `topLevelImportPaths` See styled-components/babel-plugin-styled-components@325167b Fixes styled-components/xstyled#44 Cherry picked from styled-components@83c8b0c
Quick update This has been merged now to styled-components v6 in development, see styled-components/styled-components#3422 I've also opened the PR to get it on v5 legacy, which is the current stable version, see styled-components/styled-components#3432 That's progress, but unfortunately we're still between releases. There haven't been any v6 development releases, and the last v5 release was in October 2020, so it's hard to say when this will be available for general use. Feel free to give the v5 PR a thumbs-up, it might help. In the meantime you can use |
Great news, styled-components 5.2.2 was released with this fix 🎉 https://github.com/styled-components/styled-components/releases/tag/v5.2.2 I think all we need now is an update to xstyled docs and we can close this. |
Hi, it would seem I cannot import the macro version of styled-components:
https://www.styled-components.com/docs/tooling#babel-macro
Thought trying also importing from
@xstyled/macro
but no luck.Importing directly from styled-components does work well:
Background:
We have an app based on create-react-app, not ejected, and not using rewire, because CRA supports babel macros, and I wish to utilize that ability to be able to use the
babel-plugin-styled-components
plugin.I need this so my styled-components will be generated with a real display name, to be able to access components in enzyme unit tests.
Related thread
The text was updated successfully, but these errors were encountered: