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
Alternative to Babel for NextJS 11.1 SWC toolchain #2467
Comments
any news on this? |
I’ve talked to Next maintainers and they plan to port our Babel plugin to Rust and their SWC-based plugin system. So we have to be patient and wait till they manage to do that. You must understand that this is still very early stage for them in this aspect and the plugin system is not publicly available. |
Thank you so much. Would love to see this implemented |
It wasn't clear to me that their plugin system was still closed - that's an important detail. |
Issue for Next's swc support for emotion: vercel/next.js#30804 |
I have a question that might be stupid. Why do we need a plugin for |
@EqualMa Not a stupid question and thanks for bringing this up. The Next documentation states that When using the modern JSX transform (the default in recent versions of Next), setting
So it would be cool to have an Emotion swc plugin with the same functionality as @Andarist Seems like this issue can be closed. Do you agree? |
Just for information, by having this as my root .swcrc
and also this as my root tsconfig.json
I'm able to use emotion css prop with swc and without any JSX pragma |
The plugin also provides some other goodies like auto labels, source maps, and some very minor optimizations (those are on the verge of micro-optimizations though so I wouldn't really call this a strong argument). Emotion plugin has been merged to Next 20 days ago~: vercel/next.js#34687 . You can try looking there into how you can actually use it today (I think it's possible using their canary releases). As long as that plugin is written and maintained by the Next team - you should report issues/bugs/etc there and not here. |
It looks like emotion is working as an experimental feature. You have to const nextConfig = {
reactStrictMode: true,
experimental: {
emotion: true,
},
}
module.exports = nextConfig and adding {
"compilerOptions": {
"jsxImportSource": "@emotion/react"
},
} I can confirm this works with |
@tianhuil but looks like we may need to wait until nextjs team ports this plugin to @swc/core? |
@tianhuil @mcrowder65 is that something actually planned for their plugin? Been trying to use it outside of a next-js implementation but doesn't seem straightforward. Toying around with the crate they published here: https://crates.io/crates/swc_emotion but it seems that their's is a whole fork of Are they keen on allowing for a non-nextjs-specific access to the plugin? Might not be a priority as it might drive folks away from using next.js? cc @Andarist in case you know about this also. |
(Looks like their |
I assume that the goal is to make this usable outside of Next but I might be mistaken. |
@fforres I created a emotion plugin with a |
@IvanRodriCalleja yes! This is awesome, i was clearing my afternoon to take a stab at this 🙏 |
@IvanRodriCalleja do you have a repository where you are doing that work? 🙏 |
@fforres I added an example: https://github.com/IvanRodriCalleja/emotion-swc-plugin/tree/main/exampes/with-node |
I was playing around with it but I was having troubles with Jest.
experimental: {
emotion: true,
},
transform: {
'^.+\\.(js|jsx|ts|tsx)$': [
'babel-jest',
{
presets: ['next/babel', '@emotion/babel-preset-css-prop'],
},
],
} |
I don't think you need to configure transform option because you are already enabling emotion in the |
The problem
I currently rely on the emotion babel config to add CSS prop support to my app. However, NextJS just released Next 11.1, where they use SWC instead of Babel to transpile JS. This is opt-in on their end, so I can just keep using Babel and not have a problem, but I would like to use that faster toolchain and still reap the syntactic niceness of the Emotion CSS prop without adding the JSX pragma everywhere.
Proposed solution
Some alternative that works with SWC for supporting the CSS prop; maybe a webpack plugin, since that should still be usable?
Alternative solutions
Just using the JSX pragma, sigh.
The text was updated successfully, but these errors were encountered: