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

Add SWC Plugin #144

Closed
heygrady opened this issue Feb 24, 2020 · 11 comments
Closed

Add SWC Plugin #144

heygrady opened this issue Feb 24, 2020 · 11 comments

Comments

@heygrady
Copy link

https://swc-project.github.io/docs/usage-plugin

Proposal: create an swc-plugin-macros that is similar to babel-plugin-macros

SWC is increasing in popularity. It is aiming to be a drop-in replacement for babel with some significant speed improvements. It already has a webpack loader.

There is some early interest in how it might integrate with create-react-app (facebook/create-react-app#8060). Looking at which babel plugins create-react-app uses it seems like most of those things are supported by swc (with only a few exceptions).

SWC appears to be missing support for:

  1. babel-plugin-macros (important for some of my projects)
  2. babel-plugin-transform-react-remove-prop-types (less important in TypeScript projects)
  3. babel-plugin-transform-flow-strip-types (generally SWC has no Flow support 🤷🏻‍♂️)

Generally everything else babel does for me is handled by swc preset-env (or isn't particularly vital to my projects).

@kentcdodds
Copy link
Owner

Hi @heygrady!

That sounds cool. I don't have the bandwidth to work on it myself, but if you want to do it then you're welcome to! 👍

@c-rick
Copy link

c-rick commented Dec 28, 2021

try this code, it work for me
next-twin

@conartist6
Copy link
Collaborator

What language are SWC plugins written in? Rust?

@conartist6
Copy link
Collaborator

Indeed, they are written in Rust. So macros would have to be themselves written in Rust. This may be possible, but it won't share any code or architecture with babel-plugin-macros and would require maintainers with a completely different skill set. I'm going to close this issue as it will never be actionable here. Best of luck to those looking for this functionality.

@renchap
Copy link

renchap commented Feb 7, 2022

Some update on the SWC front here: swc-project/swc#3167

TL;DR: they are integrating WASM plugin support in SWC. This means you can write your plugins in any language that can be compiled to WASM, for example Typescript with https://www.assemblyscript.org

Would this make it easier to have a macros plugin for SWC ?

@conartist6
Copy link
Collaborator

That might make it possible! May I suggest that you make a repo or chat or something for people who are interested in using or building that functionality to talk and collaborate, and you should link to it here.

@renchap
Copy link

renchap commented Feb 7, 2022

The plugin support in SWC is still an experimental work in progress. If it lives up to expectations and goes into a release, then I will see what I can do!

But I suspect that it will need to be a separate project from this one, as SWC uses a different AST than babel, so macros will probably need to be rewritten entirely

@conartist6
Copy link
Collaborator

I agree that it would be a separate project that would not be intercompatible with this one. Hence the suggestion to make a new space for interested contributors.

@matthewmatician
Copy link

Maybe this is a noob question, but wouldn't this PR have made this possible?

@conartist6
Copy link
Collaborator

@matthewmatician I mean you could always do a two-step process. Parse with babel, transpile macros, send the program to SWC, then have SWC do the rest of the transpilation.

The only question is: how you would send the program to SWC? Obviously you could print it from babel and parse in SWC. But perhaps there's a more efficient way? I can't say I understand the PR you linked well enough to know quite what its API would be. If it can do a copy in a way that's faster than a parse and print, then perhaps the perf numbers would still be favorable at the end of the day.

@arlyon
Copy link

arlyon commented Aug 19, 2022

I realise this isn't directly related, however I am working on stailwc, a swc-native version of twin.macro which serves as both

  • an example of swc's macro capabilities
  • a neat project (my build times are down ~80% compared to bazel!)
  • a living example on how to build a wasm-based swc plugin for nextjs

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

7 participants