Skip to content

Commit

Permalink
feat(plugin-react): Add possibility to specify a different set of Bab…
Browse files Browse the repository at this point in the history
…el plugins for SSR
  • Loading branch information
cyco130 committed Dec 22, 2021
1 parent a96bdd9 commit c1376b3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export interface Options {
* Babel configuration applied in both dev and prod.
*/
babel?: TransformOptions

/**
* Overrides `babel.plugins` in SSR.
*/
ssrPlugins?: TransformOptions['plugins']

/**
* @deprecated Use `babel.parserOpts.plugins` instead
*/
Expand All @@ -55,6 +61,8 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
const useAutomaticRuntime = opts.jsxRuntime !== 'classic'

const userPlugins = opts.babel?.plugins || []
const userSsrPlugins = opts.ssrPlugins || userPlugins

const userParserPlugins =
opts.parserPlugins || opts.babel?.parserOpts?.plugins || []

Expand Down Expand Up @@ -113,7 +121,9 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
const isProjectFile =
!isNodeModules && (id[0] === '\0' || id.startsWith(projectRoot + '/'))

const plugins = isProjectFile ? [...userPlugins] : []
const plugins = isProjectFile
? [...(ssr ? userSsrPlugins : userPlugins)]
: []

let useFastRefresh = false
if (!skipFastRefresh && !ssr && !isNodeModules) {
Expand Down

0 comments on commit c1376b3

Please sign in to comment.