Skip to content

Commit

Permalink
fix: 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 623ab79 commit 53af576
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { version } from '../../package.json'
import { resolveCompiler } from '../core/compiler'
import { EXPORT_HELPER_ID, helperCode } from '../core/helper'
import { transformMain } from '../core/main'
import { getResolvedScript, typeDepToSFCMap } from '../core/script'
import {
clearScriptCache,
getResolvedScript,
typeDepToSFCMap,
} from '../core/script'
import { transformStyle } from '../core/style'
import { transformTemplateAsModule } from '../core/template'
import { handleHotUpdate, handleTypeDepChange } from './handleHotUpdate'
Expand Down Expand Up @@ -397,6 +401,10 @@ export const plugin = createUnplugin<Options | undefined, false>(
}
}
},

buildEnd() {
clearScriptCache()
},
}
},
)
9 changes: 7 additions & 2 deletions src/core/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { UnpluginContextMeta } from 'unplugin'
import type { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc'

// 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 @@ -33,6 +33,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 53af576

Please sign in to comment.