-
Notifications
You must be signed in to change notification settings - Fork 65
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
How to configure SWC options? To use Stage 3 decorators, for example. #85
Comments
Hi, We decided to not support decorators for JS files: #60 (comment) Seeing how much this spec has changed make me confortable with the idea that this should not be easy to use until shipped browser. If you really want to use it with pure JS, the plugin is easy to patch |
@ArnaudBarre Thank you for your quick response. I'm actually trying to make use of Stage 3 decorators in a TypeScript (v5) project. From my understanding, Stage 3 decorators are transpiled to JS code that works in current browsers, as can be seen in the following example. If you copy-paste the transpiled output into the console, you'll see the expected output mentioned in the official TS 5.0 announcement. With that in mind, what do you think is still missing for Stage 3 decorators to be usable in a Vite/React/Typescript project? |
Oh I see. I need to look at how esbuild handles this, but as soon as esbuild also correctly handles the new decorator version for TS (maybe it already does) I will publish a major version that makes tsDecorators default to the standards |
I believe the work hasn't even started in esbuild: evanw/esbuild#104 |
Thanks for the links. I will wait a week or two to see what API will be shipped in esbuild. Maybe this will be in a breaking version of esbuild, meaning that we will need to wait for Vite core to release a version with it so that the plugin can expect it. If you want to try output the change in the meantime, you can patch the plugin to pass decoratorVersion to SWC and use |
I think it was initially thought to be ready a few months ago, followed by some normative updates:
Thank you. I'll give it a try! |
Were you able to use ecmascript decorators with vite? |
If you want to use TS decorator and auto accessor, you can try unplugin-swc import { defineConfig } from "vite";
import swc from "unplugin-swc";
export default defineConfig({
plugins: [
swc.vite({
jsc: {
parser: {
syntax: "typescript",
decorators: true,
},
transform: {
decoratorMetadata: true,
decoratorVersion: "2022-03",
react: {
runtime: "automatic",
},
},
},
}),
],
}); |
@uinz can this be used with |
esbuild 0.21.3 has implemented the ES decorator, so vite should support it by default. Try locking the esbuild version at 0.21.3 (e.g. pnpm override) |
I am using typescript so I'm not 100% that this is even directly the cause of my issue but isn't vitejs/vite-plugin-react#314 (comment) relevant for direct |
Hi,
Basically the question is this:
How can I test SWC Stage 3 decorator support when using React SWC plugin?
Some background:
SWC recently shipped with Stage 3 decorator support: https://swc.rs/docs/configuration/compilation#jsctransformdecoratorversion
I'd like to try it out with React SWC plugin, but I don't see where to pass those options. Simply creating
.swcrc
file (with the following contents) at the root of the project does nothing:I also don't see a config to pass SWC options to the React SWC plugin:
I would expect being able to pass SWC options to the React SWC plugin like so, if the options in
.swcrc
file are not picked up when using SWC via the React SWC plugin:Any help is appreciated!
The text was updated successfully, but these errors were encountered: