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

Provide the optimization plugin for Next.js #9762

Closed
kaorun343 opened this issue Nov 22, 2023 · 2 comments
Closed

Provide the optimization plugin for Next.js #9762

kaorun343 opened this issue Nov 22, 2023 · 2 comments

Comments

@kaorun343
Copy link
Contributor

Is your feature request related to a problem? Please describe.

The Current SWC plugin doesn't work well with recent Next.js.
In order to reduce bundle size in Next.js application, we have to use its babel plugin so we have to put custom babel config file, which disables SWC compiler.

Describe the solution you'd like

My suggestion is providing the optimization plugin for Next.js, which wraps babelOptimizerPlugin.
We don't have to care about SWC version mismatch.
Also, we don't have to prepare custom babel config file, so we can still get benefits from Next.js's SWC compiler.
(I'm not familier with Next.js plugin system, so this explanation might be wrong.)

Describe alternatives you've considered

No response

Is your feature request related to a problem? Please describe.

@YassinEldeeb
Copy link
Collaborator

YassinEldeeb commented Nov 23, 2023

Hey @kaorun343! The SWC issue is indeed quite a complex topic, read swc-project/swc#8315 for more context.

My suggestion is providing the optimization plugin for Next.js, which wraps babelOptimizerPlugin.
We don't have to care about SWC version mismatch.

Unfortuntely, that's not possible, babelOptimizerPlugin comes from our client-preset package which we maintain in Javascript as it's targeted towards the Babel compiler, on the other hand, Next.js compiler plugins are only written in Rust, because SWC, the underlying compiler is written in Rust, that's why we need to have a completely separate package with separate challenges for the SWC plugin.

We can't simply port it, or wrap it for Next.js usage, SWC and Babel are completely different compilers, not just with language differences, but underlying architectural design.

@kaorun343
Copy link
Contributor Author

kaorun343 commented Nov 24, 2023

Hi, @YassinEldeeb!

Thanks for your reply! 👍

I checked the other packages that provides plugins for Next.js, and I found they uses babel internally. So, it might be possible to do so, I think.

They seems setting their original webpack loader in webpack field.
If this loader approach suits client-preset optimization, the SWC version implementation might be used internally.

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

2 participants