-
Notifications
You must be signed in to change notification settings - Fork 135
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
I don't get just what it is? #4
Comments
read this for understanding the motivation behind this project facebook/create-react-app#2730 |
but i'm still a bit confused. |
You'll have to phrase your question differently then, because I don't know what you're asking beyond this. |
babel-macros defines a standard interface for libraries that want to use compile-time code transformation without requiring the user to add a babel plugin to their build system (other than babel-macros, which is ideally already in place). For instance, many css-in-js libraries have a css tagged template string function: const styles = css`
.red {
color: red;
}
`; The function compiles your css into (for example) an object with generated class names for each of the classes you defined in your css: console.log(styles); // { red: "1f-d34j8rn43y587t" } This class name can be generated at runtime (in the browser), but this has some disadvantages:
To help solve those issues, many css-in-js libraries write their own babel plugin that generates the class names at compile-time instead of runtime: // Before running through babel:
const styles = css`
.red {
color: red;
}
`;
// After running through babel, with the library-specific plugin:
const styles = { red: "1f-d34j8rn43y587t" }; If the css-in-js library supported babel-macros instead, then they wouldn't need their own babel plugin to compile these out; they could instead rely on babel-macros to do it for them. So if a user already had babel-macros installed and configured with babel, then they wouldn't need to change their babel configuration to get the compile-time benefits of the library. This would be most useful if the boilerplate they were using came with babel-macros out of the box, which is what we're hoping will be true for create-react-app in the future. Although css-in-js is the most common example, there are lots of other things you could use babel-macros for, like:
|
Thanks for that! Could you add that to the README? Very useful and helpful explanation 😀 |
Sure 👍 |
This explanation comes from response to a user question in kentcdodds#4 asking what this was for.
Thank you @suchipi and It will surely help others too |
Sorry but I didn't know where to ask this. Feel free to close this if you think it's not OK here.
The text was updated successfully, but these errors were encountered: