Skip to content

Commit

Permalink
fix: 补充静态资源base64缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
DCloud_UNI_BFC authored and fxy060608 committed Sep 19, 2024
1 parent e1ac5af commit 1ec0b91
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const urlRE = /(\?|&)url(?:&|$)/

export const chunkToEmittedAssetsMap = new WeakMap<RenderedChunk, Set<string>>()

const assetCache = new WeakMap<ResolvedConfig, Map<string, string>>()
type CacheForUrl = Map<string, string>
type CacheForBase64 = Map<string, string>
const assetCache = new WeakMap<ResolvedConfig, [CacheForUrl, CacheForBase64]>()

const assetHashToFilenameMap = new WeakMap<
ResolvedConfig,
Expand All @@ -50,7 +52,7 @@ export function assetPlugin(
name: 'vite:asset',

buildStart() {
assetCache.set(config, new Map())
assetCache.set(config, [new Map(), new Map()])
emittedHashMap.set(config, new Set())
},

Expand Down Expand Up @@ -323,7 +325,8 @@ function fileToBuiltUrl(
if (!skipPublicCheck && checkPublicFile(id, config)) {
return config.base + id.slice(1)
}
const cache = assetCache.get(config)!
const [cacheForUrl, cacheForBase64] = assetCache.get(config)!
const cache = canInline ? cacheForBase64 : cacheForUrl
const cached = cache.get(id)
if (cached) {
return cached
Expand Down

0 comments on commit 1ec0b91

Please sign in to comment.