@@ -8,12 +8,15 @@ import * as vite from 'vite'
88import type { Plugin , PluginOption , ResolvedConfig } from 'vite'
99import {
1010 addRefreshWrapper ,
11- exactRegex ,
1211 getPreambleCode ,
1312 preambleCode ,
1413 runtimePublicPath ,
1514 silenceUseClientWarning ,
1615} from '@vitejs/react-common'
16+ import {
17+ exactRegex ,
18+ makeIdFiltersToMatchWithQuery ,
19+ } from '@rolldown/pluginutils'
1720
1821const _dirname = dirname ( fileURLToPath ( import . meta. url ) )
1922
@@ -198,9 +201,11 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
198201 transform : {
199202 filter : {
200203 id : {
201- include : ensureArray ( include ) . map ( matchWithQuery ) ,
204+ include : makeIdFiltersToMatchWithQuery ( include ) ,
202205 exclude : [
203- ...( exclude ? ensureArray ( exclude ) . map ( matchWithQuery ) : [ ] ) ,
206+ ...( exclude
207+ ? makeIdFiltersToMatchWithQuery ( ensureArray ( exclude ) )
208+ : [ ] ) ,
204209 / \/ n o d e _ m o d u l e s \/ / ,
205210 ] ,
206211 } ,
@@ -448,18 +453,3 @@ function getReactCompilerRuntimeModule(
448453function ensureArray < T > ( value : T | T [ ] ) : T [ ] {
449454 return Array . isArray ( value ) ? value : [ value ]
450455}
451-
452- function matchWithQuery ( input : string | RegExp ) {
453- if ( typeof input === 'string' ) {
454- return `${ input } {?*,}`
455- }
456- return addQueryToRegex ( input )
457- }
458-
459- function addQueryToRegex ( input : RegExp ) {
460- return new RegExp (
461- // replace `$` with `(?:\?.*)?$` (ignore `\$`)
462- input . source . replace ( / (?< ! \\ ) \$ / g, '(?:\\?.*)?$' ) ,
463- input . flags ,
464- )
465- }
0 commit comments