vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
831 stars 54 forks source link

feat: add devTarget option (fixes #141) #149

Closed ArnaudBarre closed 1 year ago

ArnaudBarre commented 1 year ago

Fixes #141

The current implicit devTarget of Vite is esbuild.target, but this is disable by the plugin.

I was thinking of adding server.target to Vite core, but I'm not sure the added field will be more clear for users (given that we already ignore tsConfig targets)

bluwy commented 1 year ago

I think we can probably swallow some maintenance on converting esbuild-style targets to these (like lightningcss too). But if we ever did that, I think it's worth cleaning up targets we read, like from tsconfig#target, esbuild.target, esbuildOptions.target, css.lightningcss.targets and build.cssTarget. And only make two ways to configure it - server.target and build.target 🤔

ArnaudBarre commented 1 year ago

CSS targets is a useful additions for people targeting non mainstream browser apparently: https://vitejs.dev/config/build-options.html#build-csstarget

I don't think we read tsconfig#target currently, expect for matching esbuild behaviour for enabling other flags.

esbuild target system is not perfect so I think we should keep lightningcss.targets, it doesn't cost that much.

The only issue IMO is the fact that we you want to change the dev target, you need to change esbuildOptions.target and esbuild.target which is not intuitive but at least it's possible and it works

bluwy commented 1 year ago

The only issue IMO is the fact that we you want to change the dev target, you need to change esbuildOptions.target and esbuild.target which is not intuitive but at least it's possible and it works

That's because in most cases, the default dev target should work in most evergreen browsers without needing changing. So if you really need to, you'd reach out to those specific options.

If we were to add another new option, I think we should re-think our target approach further to make it simpler and opinionated. There's already a lot of places to configure target, which each makes sense, but not the most user-friendly thing to configure.