Skip to content

Commit

Permalink
fix: update cache key geneartion to match spec
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKruckenberg committed Mar 30, 2021
1 parent 925dfe4 commit 7f0a0e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export function loadImageFromBuffer(buf: Buffer) {
return sharp(buf)
}

export function generateImageID(config:ImageConfig) {
return createHash('sha1').update(JSON.stringify(config)).digest('hex')
export function generateImageID(url:URL, config:ImageConfig) {
const baseURL = new URL(url.origin + url.pathname)

return createHash('sha1').update(baseURL.href).update(JSON.stringify(config)).digest('hex')
}
2 changes: 1 addition & 1 deletion packages/vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function imagetools(userOptions: Partial<PluginOptions> = {}): Pl
const outputMetadatas = []

for (const config of imageConfigs) {
const id = generateImageID({ ...config, src: src.pathname })
const id = generateImageID(src, config)

const { transforms } = generateTransforms(config, directives)
const { image, metadata } = await applyTransforms(transforms, img)
Expand Down

0 comments on commit 7f0a0e8

Please sign in to comment.