wessberg / rollup-plugin-ts

A TypeScript Rollup plugin that bundles declarations, respects Browserslists, and enables seamless integration with transpilers such as babel and swc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support multiple SWC entries

hjoelh opened this issue · comments

commented

Question

Hey @wessberg, does the swc integration in this plugin support an array of options like this?
swc-project/swc#1877
https://swc.rs/docs/configuration/compilation#multiple-entries
Cannot seem to get it to work

Thank you

It does not currently support that, no. Could you provide me an example of what you want to achieve with multiple configs, maybe simply your swc config? Then I'll have a better understanding of the use case. I'll mark this as a feature request.

commented

Similar to swc-project/swc#1877
I believe you would need an array of options to allow swc to complile tsx and jsx?

The original use case from that issue, as well as the tsx/jsx use case is not relevant in the context of rollup-plugin-ts, though, as the TypeScript-specific syntax is always stripped by the TypeScript Compiler APIs, which then leaves SWC with the responsibility of continuing on from there and lowering that to whatever ES version you're targeting.

In other words, there's no point in having something like "parser": "typescript anywhere in your swc config when you use rollup-plugin-ts, as the TypeScript-specific syntax is always gone at the point in the compilation process when swc takes over.

This FAQ entry from the README explains this in more details. It's about Babel, but the same principles apply for swc.

Still, I'll see if I can support this multi-entry SWC feature, but you should know that in your case you won't actually need it, as you can just leave out the TypeScript part of your swc config.

commented

Thank you @wessberg. Does this still apply now with v3?

In v3, this is now relevant, as swc is potentially used for stripping away TypeScript features as well.

I've looked into this issue and added support for multiple swc configs. However, the original issue you linked to isn't relevant here, as you can just use syntax: "typescript" in you swc config at all times, and it will be able to parse both .js and .ts files without problems, so long as you set allowJs: true in your tsconfig.json file!

I imagine there are tons of reasons why you may want to use multiple swc configs, however, and so I'm happy to support it. It will be available in the next release, which I'll release shortly.