File tree 6 files changed +32
-8
lines changed
6 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,7 @@ export default defineBuildConfig({
8
8
rollup : {
9
9
inlineDependencies : true ,
10
10
} ,
11
+ replace : {
12
+ 'globalThis.__IS_BUILD__' : 'true' ,
13
+ } ,
11
14
} )
Original file line number Diff line number Diff line change
1
+ declare global {
2
+ /** replaced by unbuild only in build */
3
+ // eslint-disable-next-line no-var --- top level var has to be var
4
+ var __IS_BUILD__ : boolean | void
5
+ }
6
+
7
+ export { }
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ import {
12
12
13
13
const _dirname = dirname ( fileURLToPath ( import . meta. url ) )
14
14
15
+ const refreshRuntimePath = globalThis . __IS_BUILD__
16
+ ? join ( _dirname , 'refresh-runtime.js' )
17
+ : // eslint-disable-next-line n/no-unsupported-features/node-builtins -- only used in dev
18
+ fileURLToPath ( import . meta. resolve ( '@vitejs/react-common/refresh-runtime' ) )
19
+
15
20
export interface Options {
16
21
include ?: string | RegExp | Array < string | RegExp >
17
22
exclude ?: string | RegExp | Array < string | RegExp >
@@ -88,10 +93,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
88
93
load : {
89
94
filter : { id : exactRegex ( runtimePublicPath ) } ,
90
95
handler ( _id ) {
91
- return readFileSync (
92
- join ( _dirname , 'refresh-runtime.js' ) ,
93
- 'utf-8' ,
94
- ) . replace (
96
+ return readFileSync ( refreshRuntimePath , 'utf-8' ) . replace (
95
97
/ _ _ R E A D M E _ U R L _ _ / g,
96
98
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-oxc' ,
97
99
)
Original file line number Diff line number Diff line change @@ -9,4 +9,7 @@ export default defineBuildConfig({
9
9
emitCJS : true ,
10
10
inlineDependencies : true ,
11
11
} ,
12
+ replace : {
13
+ 'globalThis.__IS_BUILD__' : 'true' ,
14
+ } ,
12
15
} )
Original file line number Diff line number Diff line change
1
+ declare global {
2
+ /** replaced by unbuild only in build */
3
+ // eslint-disable-next-line no-var --- top level var has to be var
4
+ var __IS_BUILD__ : boolean | void
5
+ }
6
+
7
+ export { }
Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ import {
15
15
16
16
const _dirname = dirname ( fileURLToPath ( import . meta. url ) )
17
17
18
+ const refreshRuntimePath = globalThis . __IS_BUILD__
19
+ ? join ( _dirname , 'refresh-runtime.js' )
20
+ : // eslint-disable-next-line n/no-unsupported-features/node-builtins -- only used in dev
21
+ fileURLToPath ( import . meta. resolve ( '@vitejs/react-common/refresh-runtime' ) )
22
+
18
23
// lazy load babel since it's not used during build if plugins are not used
19
24
let babel : typeof babelCore | undefined
20
25
async function loadBabel ( ) {
@@ -297,10 +302,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
297
302
} ,
298
303
load ( id ) {
299
304
if ( id === runtimePublicPath ) {
300
- return readFileSync (
301
- join ( _dirname , 'refresh-runtime.js' ) ,
302
- 'utf-8' ,
303
- ) . replace (
305
+ return readFileSync ( refreshRuntimePath , 'utf-8' ) . replace (
304
306
/ _ _ R E A D M E _ U R L _ _ / g,
305
307
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react' ,
306
308
)
You can’t perform that action at this time.
0 commit comments