@@ -69,27 +69,27 @@ function $RefreshSig$() { return RefreshRuntime.createSignatureFunctionForTransf
69
69
}
70
70
71
71
export function virtualPreamblePlugin ( {
72
- name,
73
72
isEnabled,
74
73
} : {
75
- name : string
76
74
isEnabled : ( ) => boolean
77
75
} ) : Plugin {
76
+ const VIRTUAL_NAME = 'virtual:@vitejs/plugin-react/preamble'
78
77
return {
79
78
name : 'vite:react-virtual-preamble' ,
79
+ apply : 'serve' ,
80
80
resolveId : {
81
81
order : 'pre' ,
82
- filter : { id : exactRegex ( name ) } ,
82
+ filter : { id : exactRegex ( VIRTUAL_NAME ) } ,
83
83
handler ( source ) {
84
- if ( source === name ) {
84
+ if ( source === VIRTUAL_NAME ) {
85
85
return '\0' + source
86
86
}
87
87
} ,
88
88
} ,
89
89
load : {
90
- filter : { id : exactRegex ( '\0' + name ) } ,
90
+ filter : { id : exactRegex ( '\0' + VIRTUAL_NAME ) } ,
91
91
handler ( id ) {
92
- if ( id === '\0' + name ) {
92
+ if ( id === '\0' + VIRTUAL_NAME ) {
93
93
if ( isEnabled ( ) ) {
94
94
// vite dev import analysis can rewrite base
95
95
return preambleCode . replace ( '__BASE__' , '/' )
@@ -102,9 +102,10 @@ export function virtualPreamblePlugin({
102
102
filter : { code : / _ _ R E A C T _ D E V T O O L S _ G L O B A L _ H O O K _ _ / } ,
103
103
handler ( code , _id , options ) {
104
104
if ( options ?. ssr ) return
105
+
105
106
// this is expected to be either `react` or `react-dom/client`
106
107
if ( isEnabled ( ) && code . includes ( '__REACT_DEVTOOLS_GLOBAL_HOOK__' ) ) {
107
- return `import ${ JSON . stringify ( name ) } ;` + code
108
+ return `import ${ JSON . stringify ( VIRTUAL_NAME ) } ;` + code
108
109
}
109
110
} ,
110
111
} ,
0 commit comments