mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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) {
|
||||
const identifier = map.get(component) || `__nuxt_component_${num++}`
|
||||
map.set(component, identifier)
|
||||
imports += genImport(component.filePath, identifier)
|
||||
imports += genImport(component.filePath, [{ name: component.export, as: identifier }])
|
||||
return ` ${identifier}`
|
||||
}
|
||||
// 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 { addComponent } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
buildDir: process.env.NITRO_BUILD_DIR,
|
||||
@ -9,5 +10,14 @@ export default defineNuxtConfig({
|
||||
// @ts-ignore TODO: Fix schema types
|
||||
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>
|
||||
<h1>Hello Vue 3</h1>
|
||||
<div>Config: {{ $config.testConfig }}</div>
|
||||
<CustomComponent />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user