mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt3): generate imports for components with named exports correctly (#3288)
This commit is contained in:
parent
65d16a58c0
commit
8adff2edf7
@ -37,7 +37,7 @@ function transform (content: string, components: Component[]) {
|
|||||||
if (component) {
|
if (component) {
|
||||||
const identifier = map.get(component) || `__nuxt_component_${num++}`
|
const identifier = map.get(component) || `__nuxt_component_${num++}`
|
||||||
map.set(component, identifier)
|
map.set(component, identifier)
|
||||||
imports += genImport(component.filePath, identifier)
|
imports += genImport(component.filePath, [{ name: component.export, as: identifier }])
|
||||||
return ` ${identifier}`
|
return ` ${identifier}`
|
||||||
}
|
}
|
||||||
// no matched
|
// no matched
|
||||||
|
12
test/fixtures/basic/nuxt.config.ts
vendored
12
test/fixtures/basic/nuxt.config.ts
vendored
@ -1,4 +1,5 @@
|
|||||||
import { defineNuxtConfig } from 'nuxt3'
|
import { defineNuxtConfig } from 'nuxt3'
|
||||||
|
import { addComponent } from '@nuxt/kit'
|
||||||
|
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
buildDir: process.env.NITRO_BUILD_DIR,
|
buildDir: process.env.NITRO_BUILD_DIR,
|
||||||
@ -9,5 +10,14 @@ export default defineNuxtConfig({
|
|||||||
// @ts-ignore TODO: Fix schema types
|
// @ts-ignore TODO: Fix schema types
|
||||||
testConfig: '123'
|
testConfig: '123'
|
||||||
},
|
},
|
||||||
modules: ['~/modules/example']
|
modules: ['~/modules/example'],
|
||||||
|
hooks: {
|
||||||
|
'modules:done' () {
|
||||||
|
addComponent({
|
||||||
|
name: 'CustomComponent',
|
||||||
|
export: 'namedExport',
|
||||||
|
filePath: '~/other-components-folder/named-export'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
3
test/fixtures/basic/other-components-folder/named-export.ts
vendored
Normal file
3
test/fixtures/basic/other-components-folder/named-export.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const namedExport = defineComponent({
|
||||||
|
setup: () => () => h('div', 'This is a custom component with a named export.')
|
||||||
|
})
|
1
test/fixtures/basic/pages/index.vue
vendored
1
test/fixtures/basic/pages/index.vue
vendored
@ -5,6 +5,7 @@
|
|||||||
</Head>
|
</Head>
|
||||||
<h1>Hello Vue 3</h1>
|
<h1>Hello Vue 3</h1>
|
||||||
<div>Config: {{ $config.testConfig }}</div>
|
<div>Config: {{ $config.testConfig }}</div>
|
||||||
|
<CustomComponent />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user