Skip to content

Commit 9b1b510

Browse files
authored
chore: fix refresh runtime path in dev (#444)
1 parent c1b9264 commit 9b1b510

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

packages/plugin-react-oxc/build.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ export default defineBuildConfig({
88
rollup: {
99
inlineDependencies: true,
1010
},
11+
replace: {
12+
'globalThis.__IS_BUILD__': 'true',
13+
},
1114
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 {}

packages/plugin-react-oxc/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import {
1212

1313
const _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+
1520
export 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
/__README_URL__/g,
9698
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-oxc',
9799
)

packages/plugin-react/build.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

packages/plugin-react/src/build.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 {}

packages/plugin-react/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import {
1515

1616
const _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
1924
let babel: typeof babelCore | undefined
2025
async 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
/__README_URL__/g,
305307
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react',
306308
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy