Skip to content

Conversation

@YarnSphere
Copy link
Contributor

Description

When useAtYourOwnRisk_mutateSwcOptions is provided, Vite's React SWC plugin should opt into the SWC code path, rather than using esbuild.

The current workaround when changing SWC options while not specifying SWC plugins is to provide an empty plugins array.

Lost quite a few hours playing with configurations to reach my end-goal of preserving JSDoc comments in the produced output (something not supported by esbuild), not understanding why overriding SWC options seemingly had no effect.

I.e., the following currently has no effect when building:

react({
  useAtYourOwnRisk_mutateSwcOptions: (options) => {
    options.jsc.preserveAllComments = true;
  }
})

The current workaround is to specify an empty plugins array:

react({
  plugins: [],
  useAtYourOwnRisk_mutateSwcOptions: (options) => {
    options.jsc.preserveAllComments = true;
  }
}),

I understand that my use-case is quite unique, but I still found the current behaviour unexpected.

Note: This commit only touches the SWC plugin. The Babel-backed plugin has a similar issue where the provided Babel configuration is sometimes completely ignored (this seemed intentional due to the canSkipBabel function, so I decided not to touch that plugin).

…provided

When `useAtYourOwnRisk_mutateSwcOptions` is provided, Vite's React SWC
plugin should opt into the SWC code path, rather than using esbuild.

The current workaround when changing SWC options while not specifying
SWC plugins is to provide an empty `plugins` array.

Example use-case: preserving comments in the output.
@ArnaudBarre
Copy link
Member

Thanks @YarnSphere
@sapphi-red This is quite an oversight from me, seems good to merge and release soon!

@sapphi-red sapphi-red merged commit 6c05743 into vitejs:main Oct 24, 2025
8 checks passed
@sapphi-red
Copy link
Member

Released in plugin-react-swc 4.2.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants