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

Feature request: support the plugin option for swc compiler #35156

Closed
wants to merge 2 commits into from

Conversation

mattcasey
Copy link

@mattcasey mattcasey commented Mar 8, 2022

I'm a bit out of my depth here. I am trying to integrate swc-plugin-transform-import into my Next.js build so that our imports of @mui are converted into default exports. The only solution that works is to fall back to the Babel compiler and use babel-plugin-transform-imports.

I couldn't find definitive documentation about the API from swc, but it seems like they support a 'plugin' option which allows transformations in Javascript. This is also based on what I've seen in the links i shared below. With the changes I've included, I can see that my plugin is getting passed to the 'transform' method of the SWC binary on my machine: swc-darwin-x64 but my investigation ends there. I can tell that my plugin function is still not being called, but I'm hoping it's a simple fix maybe to continue passing the plugin function down into swc.

The code I've added to next.config.js can be found here: #30862 (comment). I am trying to apply the plugin to the next-swc-loader. I tried adding a new rule, tried using swc-loader, etc. but ran into other issues, so I'm just asking for next-swc-loader to support this additional field instead.

Two related issues posted against next.js related to people wanting to transform their imports:

Other links:

@timneutkens
Copy link
Member

There's a PR open to add support for mapping urls with SWC: #34969

The plugins key that you're referring to is a swc-loader feature that is intentionally not supported in Next.js as it requires passing from Rust -> JS -> Rust -> JS which has a massive performance overhead. We're also working on Rust-based plugins for SWC which would solve other cases but for your case you'll probably want what we're adding in #34969.

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment.

@mattcasey
Copy link
Author

OK, thanks! Will close my PR, looking forward to the update

@mattcasey mattcasey closed this Mar 10, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants