Skip to content

Commit

Permalink
chore: make duplicates weakmap
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Sep 5, 2022
1 parent 60d024d commit 12e4548
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/asset.ts
Expand Up @@ -21,7 +21,7 @@ import { FS_PREFIX } from '../constants'

export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g

export const duplicateAssets: OutputAsset[] = []
export const duplicateAssets = new WeakMap<ResolvedConfig, OutputAsset[]>()

const rawRE = /(\?|&)raw(?:&|$)/
const urlRE = /(\?|&)url(?:&|$)/
Expand Down Expand Up @@ -132,6 +132,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
buildStart() {
assetCache.set(config, new Map())
emittedHashMap.set(config, new Set())
duplicateAssets.set(config, [])
},

resolveId(id) {
Expand Down Expand Up @@ -473,6 +474,7 @@ async function fileToBuiltUrl(
map.set(contentHash, fileName)
}
const emittedSet = emittedHashMap.get(config)!
const duplicates = duplicateAssets.get(config)!
const name = normalizePath(path.relative(config.root, file))
if (!emittedSet.has(contentHash)) {
pluginContext.emitFile({
Expand All @@ -483,7 +485,7 @@ async function fileToBuiltUrl(
})
emittedSet.add(contentHash)
} else {
duplicateAssets.push({
duplicates.push({
name,
fileName: map.get(contentHash)!,
type: 'asset',
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/manifest.ts
Expand Up @@ -123,7 +123,7 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
}
}

duplicateAssets.forEach((asset) => {
duplicateAssets.get(config)!.forEach((asset) => {
const chunk = createAsset(asset)
manifest[asset.name!] = chunk
})
Expand Down

0 comments on commit 12e4548

Please sign in to comment.