Skip to content

Commit

Permalink
fix(plugin-vue): clear cache after build end
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jul 23, 2024
1 parent 02a3edd commit 96dbb22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getSrcDescriptor,
getTempSrcDescriptor,
} from './utils/descriptorCache'
import { getResolvedScript, typeDepToSFCMap } from './script'
import { clearScriptCache, getResolvedScript, typeDepToSFCMap } from './script'
import { transformMain } from './main'
import { handleHotUpdate, handleTypeDepChange } from './handleHotUpdate'
import { transformTemplateAsModule } from './template'
Expand Down Expand Up @@ -361,5 +361,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin<Api> {
}
}
},
buildEnd() {
clearScriptCache()
},
}
}
9 changes: 7 additions & 2 deletions packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { cache as descriptorCache } from './utils/descriptorCache'
import type { ResolvedOptions } from '.'

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

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

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

export function clearScriptCache(): void {
clientCache = new WeakMap()
ssrCache = new WeakMap()
}

// Check if we can use compile template as inlined render function
// inside <script setup>. This can only be done for build because
// inlined template cannot be individually hot updated.
Expand Down

0 comments on commit 96dbb22

Please sign in to comment.