loadable-components icon indicating copy to clipboard operation
loadable-components copied to clipboard

Add SWC Plugin

Open heygrady opened this issue 4 years ago • 12 comments

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

Proposal: create an @loadable/swc-plugin that is similar to @loadable/babel-plugin

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 (https://github.com/facebook/create-react-app/issues/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).

Looking at my own projects, I see only a few things that are blocking me from switching to SWC.

  1. No support for babel-plugin-macros (which I could live without)
  2. No support for @loadable/babel-plugin

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

heygrady avatar Feb 24 '20 18:02 heygrady

Hey @heygrady :wave:, Thank you for opening an issue. We'll get back to you as soon as we can. Please, consider supporting us on Open Collective. We give a special attention to issues opened by backers. If you use Loadable at work, you can also ask your company to sponsor us :heart:.

Cross linking: https://github.com/kentcdodds/babel-plugin-macros/issues/144

heygrady avatar Feb 24 '20 18:02 heygrady

It looks great, any PR is welcome!

gregberge avatar Feb 24 '20 19:02 gregberge

Look like here is the documentation - https://swc-project.github.io/docs/usage-plugin SWC is written in rust, however, plugin system exposed in JS... so eventually swc would become a ~dragon~ babel it was created to kill.

theKashey avatar Feb 24 '20 21:02 theKashey

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 24 '20 21:04 stale[bot]

Did anyone have a chance to look at this yet?

Look like here is the documentation - https://swc-project.github.io/docs/usage-plugin SWC is written in rust, however, plugin system exposed in JS... so eventually swc would become a ~dragon~ babel it was created to kill.

The plugin api's might be deprecated in the next versions of swc.

Warning: Passing the AST to the JS Plugin system is a performance bottleneck.

Therefore, we are concidering two approaches for the next SWC major version:

Creating a plugin system in Rust (#2337) Solve the bottleneck to keep a JS plugin system (#2175)

With that said, I believe the loadable plugin would be similar to the dynamic plugin from next.js.

paul-vd avatar Oct 31 '21 22:10 paul-vd

We're in the same boat over here. I was looking at what would be needed to do this, but, I don't have enough knowledge with AST or the time available (unless I get granted time during work) to do this.

This is (AFAIK) the only thing that's stopping us from migrating over to SWC as well.

marwan38 avatar Nov 25 '21 03:11 marwan38

This is (AFAIK) the only thing that's stopping us from migrating over to SWC as well.

same here - updated links to Next.js implementation https://github.com/vercel/next.js/blob/canary/packages/next-swc/crates/core/src/next_dynamic.rs

Perni1984 avatar Nov 30 '21 07:11 Perni1984

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 05:04 stale[bot]

Perhaps a workaround could be to use babel only on the files containing @lodable() statements? For example by naming them something like MyComponent.loadable.tsx (to make it easy to differenciate the babel-loader & swc-loader).

aplassen avatar Apr 26 '22 16:04 aplassen

That is a good option and actually can lead to a better visibility over bundle structure.

theKashey avatar Apr 28 '22 10:04 theKashey

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 10 '22 21:07 stale[bot]

See https://github.com/swc-project/plugins/pull/76

ashsearle avatar Aug 22 '22 10:08 ashsearle

And https://github.com/gregberge/loadable-components/issues/909

theKashey avatar Aug 23 '22 05:08 theKashey