@@ -14,20 +14,30 @@ window.$RefreshSig$ = () => (type) => type;`
1414export const getPreambleCode = ( base : string ) : string =>
1515 preambleCode . replace ( '__BASE__' , base )
1616
17- export function addRefreshWrapper < M extends { mappings : string } | undefined > (
17+ export const avoidSourceMapOption = Symbol ( )
18+
19+ export function addRefreshWrapper < M extends { mappings : string } > (
1820 code : string ,
19- map : M | string ,
21+ map : M | string | undefined | typeof avoidSourceMapOption ,
2022 pluginName : string ,
2123 id : string ,
22- ) : { code : string ; map : M | string } {
24+ ) : { code : string ; map : M | undefined | string } {
2325 const hasRefresh = refreshContentRE . test ( code )
2426 const onlyReactComp = ! hasRefresh && reactCompRE . test ( code )
25- if ( ! hasRefresh && ! onlyReactComp ) return { code, map }
27+ const newMap =
28+ map === avoidSourceMapOption
29+ ? undefined
30+ : typeof map === 'string'
31+ ? ( JSON . parse ( map ) as M )
32+ : map
33+ if ( ! hasRefresh && ! onlyReactComp ) return { code, map : newMap }
34+
35+ const avoidSourceMap = map === avoidSourceMapOption
2636
27- const newMap = typeof map === 'string' ? ( JSON . parse ( map ) as M ) : map
2837 let newCode = code
2938 if ( hasRefresh ) {
30- newCode = `let prevRefreshReg;
39+ const refreshHead = removeLineBreaksIfNeeded (
40+ `let prevRefreshReg;
3141let prevRefreshSig;
3242
3343if (import.meta.hot && !inWebWorker) {
@@ -43,7 +53,11 @@ if (import.meta.hot && !inWebWorker) {
4353 window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
4454}
4555
46- ${ newCode }
56+ ` ,
57+ avoidSourceMap ,
58+ )
59+
60+ newCode = `${ refreshHead } ${ newCode }
4761
4862if (import.meta.hot && !inWebWorker) {
4963 window.$RefreshReg$ = prevRefreshReg;
@@ -55,10 +69,15 @@ if (import.meta.hot && !inWebWorker) {
5569 }
5670 }
5771
58- newCode = `import * as RefreshRuntime from "${ runtimePublicPath } ";
72+ const sharedHead = removeLineBreaksIfNeeded (
73+ `import * as RefreshRuntime from "${ runtimePublicPath } ";
5974const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
6075
61- ${ newCode }
76+ ` ,
77+ avoidSourceMap ,
78+ )
79+
80+ newCode = `${ sharedHead } ${ newCode }
6281
6382if (import.meta.hot && !inWebWorker) {
6483 RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
@@ -81,3 +100,7 @@ if (import.meta.hot && !inWebWorker) {
81100
82101 return { code : newCode , map : newMap }
83102}
103+
104+ function removeLineBreaksIfNeeded ( code : string , enabled : boolean ) : string {
105+ return enabled ? code . replace ( / \n / g, '' ) : code
106+ }
0 commit comments