File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
packages/plugin-react/src Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change
1
+ // eslint-disable-next-line import/no-duplicates
2
+ import type * as babelCore from '@babel/core'
3
+ // eslint-disable-next-line import/no-duplicates
1
4
import type { ParserOptions , TransformOptions } from '@babel/core'
2
- import * as babel from '@babel/core'
3
5
import { createFilter } from 'vite'
4
6
import type {
5
7
BuildOptions ,
@@ -15,6 +17,15 @@ import {
15
17
runtimePublicPath ,
16
18
} from './fast-refresh'
17
19
20
+ // lazy load babel since it's not used during build if plugins are not used
21
+ let babel : typeof babelCore | undefined
22
+ async function loadBabel ( ) {
23
+ if ( ! babel ) {
24
+ babel = await import ( '@babel/core' )
25
+ }
26
+ return babel
27
+ }
28
+
18
29
export interface Options {
19
30
include ?: string | RegExp | Array < string | RegExp >
20
31
exclude ?: string | RegExp | Array < string | RegExp >
@@ -215,6 +226,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
215
226
parserPlugins . push ( 'typescript' )
216
227
}
217
228
229
+ const babel = await loadBabel ( )
218
230
const result = await babel . transformAsync ( code , {
219
231
...babelOptions ,
220
232
root : projectRoot ,
You can’t perform that action at this time.
0 commit comments