@@ -28,10 +28,12 @@ window.$RefreshSig$ = () => (type) => type
28
28
window.__vite_plugin_react_preamble_installed__ = true
29
29
`
30
30
31
- const header = `
31
+ const sharedHeader = `
32
32
import RefreshRuntime from "${ runtimePublicPath } ";
33
33
34
34
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
35
+ ` . replace ( / \n + / g, '' )
36
+ const functionHeader = `
35
37
let prevRefreshReg;
36
38
let prevRefreshSig;
37
39
@@ -51,11 +53,13 @@ if (import.meta.hot && !inWebWorker) {
51
53
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
52
54
}` . replace ( / \n + / g, '' )
53
55
54
- const footer = `
56
+ const functionFooter = `
55
57
if (import.meta.hot && !inWebWorker) {
56
58
window.$RefreshReg$ = prevRefreshReg;
57
59
window.$RefreshSig$ = prevRefreshSig;
58
-
60
+ }`
61
+ const sharedFooter = `
62
+ if (import.meta.hot && !inWebWorker) {
59
63
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
60
64
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
61
65
import.meta.hot.accept((nextExports) => {
@@ -68,8 +72,19 @@ if (import.meta.hot && !inWebWorker) {
68
72
69
73
export function addRefreshWrapper ( code : string , id : string ) : string {
70
74
return (
71
- header . replace ( '__SOURCE__' , JSON . stringify ( id ) ) +
75
+ sharedHeader +
76
+ functionHeader . replace ( '__SOURCE__' , JSON . stringify ( id ) ) +
72
77
code +
73
- footer . replace ( '__SOURCE__' , JSON . stringify ( id ) )
78
+ functionFooter +
79
+ sharedFooter . replace ( '__SOURCE__' , JSON . stringify ( id ) )
80
+ )
81
+ }
82
+
83
+ export function addClassComponentRefreshWrapper (
84
+ code : string ,
85
+ id : string ,
86
+ ) : string {
87
+ return (
88
+ sharedHeader + code + sharedFooter . replace ( '__SOURCE__' , JSON . stringify ( id ) )
74
89
)
75
90
}
0 commit comments