vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
778 stars 50 forks source link

Feature request: configure swc's `target` property #141

Closed mbeckem closed 9 months ago

mbeckem commented 10 months ago

Hi,

during developement this plugin currently applies target: "es2020" to swc's JscTarget with no way to change the language level.

In our case this results in JavaScript's private fields being transpiled into WeakMaps, even though all major browser support this feature by now (this makes debugging classes using private fields very unpleasant).

It would help a lot if the plugin would support a target option, e.g.

react({ target: "2022" });

Alternatively, the default target could simply be raised.

Just out of curiosity, why does the plugin's transform hook run on "plain" .ts files (no JSX)?

Thanks!

ArnaudBarre commented 10 months ago

Related: https://github.com/vitejs/vite-plugin-react-swc/discussions/138

I think the problem is to be solved at the core level. I need to investigate but I might push it in the next major coming in September.

The reason I used 2020 is to avoid having your dev env working in one browser but not another just because you use a new syntax. If the problem is not solved in core, I will bump it in this package to what Safari 15 as implemented at this time.

In the meantime I think using a one line patch is the best solution (using pnpm or patch-package)

It's enabled on TS to allow to disable esbuild completely, otherwise esbuild will run on SWC output for TSX. It's also expected for people using plugins.

mbeckem commented 10 months ago

Thank you for the explanation. A patch via pnpm is exactly what we're doing in the meantime.