fix(vite, webpack): generate composable keys based on order (#6191)

This commit is contained in:
Daniel Roe 2022-07-29 10:40:04 +01:00 committed by GitHub
parent d4eba42f17
commit 3f2eb3a3b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,7 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || []
const s = new MagicString(code)
// https://github.com/unjs/unplugin/issues/90
let count = 0
const relativeID = isAbsolute(id) ? relative(options.rootDir, id) : id
walk(this.parse(script, {
sourceType: 'module',
@ -39,7 +40,7 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
const end = (node as any).end
s.appendLeft(
codeIndex + end - 1,
(node.arguments.length ? ', ' : '') + "'$" + hash(`${relativeID}-${codeIndex + end}`) + "'"
(node.arguments.length ? ', ' : '') + "'$" + hash(`${relativeID}-${++count}`) + "'"
)
}
}