Skip to content

How to configure SWC options? To use Stage 3 decorators, for example. #85

Closed as not planned
@yay

Description

@yay

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:

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "decorators": true
    },
    "transform": {
      "decoratorVersion": "2022-03"
    }
  }
}

I also don't see a config to pass SWC options to the React SWC plugin:

import { PluginOption } from "vite";
type Options = {
    /**
     * Control where the JSX factory is imported from.
     * @default "react"
     */
    jsxImportSource?: string;
    /**
     * Enable TypeScript decorators. Requires experimentalDecorators in tsconfig.
     * @default false
     */
    tsDecorators?: boolean;
    /**
     * Use SWC plugins. Enable SWC at build time.
     * @default undefined
     */
    plugins?: [string, Record<string, any>][];
};
declare const react: (_options?: Options) => PluginOption[];
export default react;

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:

plugins: [react({
  swcOptions: {
    "jsc": {
      "parser": {
        "syntax": "ecmascript",
        "decorators": true
      },
      "transform": {
        "decoratorVersion": "2022-03"
      }
    }
  }
})],

Any help is appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions