File tree Expand file tree Collapse file tree 6 files changed +32
-8
lines changed Expand file tree Collapse file tree 6 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,7 @@ export default defineBuildConfig({
88 rollup : {
99 inlineDependencies : true ,
1010 } ,
11+ replace : {
12+ 'globalThis.__IS_BUILD__' : 'true' ,
13+ } ,
1114} )
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 {
1212
1313const _dirname = dirname ( fileURLToPath ( import . meta. url ) )
1414
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+
1520export interface Options {
1621 include ?: string | RegExp | Array < string | RegExp >
1722 exclude ?: string | RegExp | Array < string | RegExp >
@@ -88,10 +93,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
8893 load : {
8994 filter : { id : exactRegex ( runtimePublicPath ) } ,
9095 handler ( _id ) {
91- return readFileSync (
92- join ( _dirname , 'refresh-runtime.js' ) ,
93- 'utf-8' ,
94- ) . replace (
96+ return readFileSync ( refreshRuntimePath , 'utf-8' ) . replace (
9597 / _ _ R E A D M E _ U R L _ _ / g,
9698 'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-oxc' ,
9799 )
Original file line number Diff line number Diff line change @@ -9,4 +9,7 @@ export default defineBuildConfig({
99 emitCJS : true ,
1010 inlineDependencies : true ,
1111 } ,
12+ replace : {
13+ 'globalThis.__IS_BUILD__' : 'true' ,
14+ } ,
1215} )
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 {
1515
1616const _dirname = dirname ( fileURLToPath ( import . meta. url ) )
1717
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+
1823// lazy load babel since it's not used during build if plugins are not used
1924let babel : typeof babelCore | undefined
2025async function loadBabel ( ) {
@@ -297,10 +302,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
297302 } ,
298303 load ( id ) {
299304 if ( id === runtimePublicPath ) {
300- return readFileSync (
301- join ( _dirname , 'refresh-runtime.js' ) ,
302- 'utf-8' ,
303- ) . replace (
305+ return readFileSync ( refreshRuntimePath , 'utf-8' ) . replace (
304306 / _ _ R E A D M E _ U R L _ _ / g,
305307 'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react' ,
306308 )
You can’t perform that action at this time.
0 commit comments