Skip to content

Commit 53af576

Browse files
committed
fix: clear cache after build end
1 parent 623ab79 commit 53af576

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/core/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import { version } from '../../package.json'
1111
import { resolveCompiler } from '../core/compiler'
1212
import { EXPORT_HELPER_ID, helperCode } from '../core/helper'
1313
import { transformMain } from '../core/main'
14-
import { getResolvedScript, typeDepToSFCMap } from '../core/script'
14+
import {
15+
clearScriptCache,
16+
getResolvedScript,
17+
typeDepToSFCMap,
18+
} from '../core/script'
1519
import { transformStyle } from '../core/style'
1620
import { transformTemplateAsModule } from '../core/template'
1721
import { handleHotUpdate, handleTypeDepChange } from './handleHotUpdate'
@@ -397,6 +401,10 @@ export const plugin = createUnplugin<Options | undefined, false>(
397401
}
398402
}
399403
},
404+
405+
buildEnd() {
406+
clearScriptCache()
407+
},
400408
}
401409
},
402410
)

src/core/script.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { UnpluginContextMeta } from 'unplugin'
55
import type { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc'
66

77
// ssr and non ssr builds would output different script content
8-
const clientCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()
9-
const ssrCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()
8+
let clientCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()
9+
let ssrCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()
1010

1111
export const typeDepToSFCMap = new Map<string, Set<string>>()
1212

@@ -33,6 +33,11 @@ export function setResolvedScript(
3333
;(ssr ? ssrCache : clientCache).set(descriptor, script)
3434
}
3535

36+
export function clearScriptCache(): void {
37+
clientCache = new WeakMap()
38+
ssrCache = new WeakMap()
39+
}
40+
3641
// Check if we can use compile template as inlined render function
3742
// inside <script setup>. This can only be done for build because
3843
// inlined template cannot be individually hot updated.

0 commit comments

Comments
 (0)