Skip to content

Commit 96dbb22

Browse files
committed
fix(plugin-vue): clear cache after build end
1 parent 02a3edd commit 96dbb22

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/plugin-vue/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
getSrcDescriptor,
2020
getTempSrcDescriptor,
2121
} from './utils/descriptorCache'
22-
import { getResolvedScript, typeDepToSFCMap } from './script'
22+
import { clearScriptCache, getResolvedScript, typeDepToSFCMap } from './script'
2323
import { transformMain } from './main'
2424
import { handleHotUpdate, handleTypeDepChange } from './handleHotUpdate'
2525
import { transformTemplateAsModule } from './template'
@@ -361,5 +361,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin<Api> {
361361
}
362362
}
363363
},
364+
buildEnd() {
365+
clearScriptCache()
366+
},
364367
}
365368
}

packages/plugin-vue/src/script.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { cache as descriptorCache } from './utils/descriptorCache'
44
import type { ResolvedOptions } from '.'
55

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

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

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

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

0 commit comments

Comments
 (0)