@@ -340,43 +340,43 @@ export default function viteReact(opts: Options = {}): Plugin[] {
340
340
} ,
341
341
}
342
342
343
+ // for rolldown-vite
343
344
const viteRefreshWrapper : Plugin = {
344
345
name : 'vite:react:refresh-wrapper' ,
345
346
apply : 'serve' ,
346
- transform : isRolldownVite
347
- ? {
348
- filter : {
349
- id : {
350
- include : makeIdFiltersToMatchWithQuery ( include ) ,
351
- exclude : makeIdFiltersToMatchWithQuery ( exclude ) ,
352
- } ,
353
- } ,
354
- handler ( code , id , options ) {
355
- const ssr = options ?. ssr === true
356
-
357
- const [ filepath ] = id . split ( '?' )
358
- const isJSX = filepath . endsWith ( 'x' )
359
- const useFastRefresh =
360
- ! skipFastRefresh &&
361
- ! ssr &&
362
- ( isJSX ||
363
- code . includes ( jsxImportDevRuntime ) ||
364
- code . includes ( jsxImportRuntime ) )
365
- if ( ! useFastRefresh ) return
366
-
367
- const { code : newCode } = addRefreshWrapper (
368
- code ,
369
- avoidSourceMapOption ,
370
- '@vitejs/plugin-react' ,
371
- id ,
372
- opts . reactRefreshHost ,
373
- )
374
- return { code : newCode , map : null }
375
- } ,
376
- }
377
- : undefined ,
347
+ transform : {
348
+ filter : {
349
+ id : {
350
+ include : makeIdFiltersToMatchWithQuery ( include ) ,
351
+ exclude : makeIdFiltersToMatchWithQuery ( exclude ) ,
352
+ } ,
353
+ } ,
354
+ handler ( code , id , options ) {
355
+ const ssr = options ?. ssr === true
356
+
357
+ const [ filepath ] = id . split ( '?' )
358
+ const isJSX = filepath . endsWith ( 'x' )
359
+ const useFastRefresh =
360
+ ! skipFastRefresh &&
361
+ ! ssr &&
362
+ ( isJSX ||
363
+ code . includes ( jsxImportDevRuntime ) ||
364
+ code . includes ( jsxImportRuntime ) )
365
+ if ( ! useFastRefresh ) return
366
+
367
+ const { code : newCode } = addRefreshWrapper (
368
+ code ,
369
+ avoidSourceMapOption ,
370
+ '@vitejs/plugin-react' ,
371
+ id ,
372
+ opts . reactRefreshHost ,
373
+ )
374
+ return { code : newCode , map : null }
375
+ } ,
376
+ } ,
378
377
}
379
378
379
+ // for rolldown-vite
380
380
const viteConfigPost : Plugin = {
381
381
name : 'vite:react:config-post' ,
382
382
enforce : 'post' ,
@@ -449,7 +449,11 @@ export default function viteReact(opts: Options = {}): Plugin[] {
449
449
} ,
450
450
}
451
451
452
- return [ viteBabel , viteRefreshWrapper , viteConfigPost , viteReactRefresh ]
452
+ return [
453
+ viteBabel ,
454
+ ...( isRolldownVite ? [ viteRefreshWrapper , viteConfigPost ] : [ ] ) ,
455
+ viteReactRefresh ,
456
+ ]
453
457
}
454
458
455
459
viteReact . preambleCode = preambleCode
0 commit comments