fix(nuxt): allow auto-import component with same filename (#7713)

This commit is contained in:
Daniel Roe 2022-10-03 14:38:43 +01:00 committed by GitHub
parent c11630328d
commit a3fd4193ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -65,7 +65,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
const s = new MagicString(code)
// replace `_resolveComponent("...")` to direct import
s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy)?([^'"]*?)["'][\s,]*\)/g, (full, lazy, name) => {
s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy)?([^'"]*?)["'][\s,]*[^)]*\)/g, (full, lazy, name) => {
const component = findComponent(components, name, options.mode)
if (component) {
let identifier = map.get(component) || `__nuxt_component_${num++}`

View File

@ -0,0 +1,11 @@
<script setup lang="ts">
defineProps({
count: Number
})
</script>
<template>
<div>
<SugarCounter :count="count" />
</div>
</template>

View File

@ -12,7 +12,7 @@
<NuxtLink to="/">
Link
</NuxtLink>
<SugarCounter :count="12" />
<NestedSugarCounter :count="12" />
<CustomComponent />
<component :is="`test${'-'.toString()}global`" />
<component :is="`with${'-'.toString()}suffix`" />