mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
feat(nuxt): support auto imports within <template>
(#4904)
This commit is contained in:
parent
4e2dc037aa
commit
a802b87ac7
@ -36,7 +36,10 @@ export default defineNuxtModule<Partial<AutoImportsOptions>>({
|
||||
// Create a context to share state between module internals
|
||||
const ctx = createUnimport({
|
||||
presets: options.presets,
|
||||
imports: options.imports
|
||||
imports: options.imports,
|
||||
addons: {
|
||||
vueTemplate: true
|
||||
}
|
||||
})
|
||||
|
||||
// composables/ dirs from all layers
|
||||
|
@ -39,7 +39,7 @@ export const TransformPlugin = createUnplugin(({ ctx, options, sourcemap }: {ctx
|
||||
}
|
||||
},
|
||||
async transform (_code, id) {
|
||||
const { code, s } = await ctx.injectImports(_code)
|
||||
const { code, s } = await ctx.injectImports(_code, id)
|
||||
if (code === _code) {
|
||||
return
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ describe('pages', () => {
|
||||
// composables auto import
|
||||
expect(html).toContain('Composable | foo: auto imported from ~/components/foo.ts')
|
||||
expect(html).toContain('Composable | bar: auto imported from ~/components/useBar.ts')
|
||||
expect(html).toContain('Composable | template: auto imported from ~/components/template.ts')
|
||||
// should import components
|
||||
expect(html).toContain('This is a custom component with a named export.')
|
||||
|
||||
|
1
test/fixtures/basic/composables/template.ts
vendored
Normal file
1
test/fixtures/basic/composables/template.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export const templateAutoImport = 'auto imported from ~/components/template.ts'
|
1
test/fixtures/basic/pages/index.vue
vendored
1
test/fixtures/basic/pages/index.vue
vendored
@ -7,6 +7,7 @@
|
||||
<div>RuntimeConfig | testConfig: {{ config.testConfig }}</div>
|
||||
<div>Composable | foo: {{ foo }}</div>
|
||||
<div>Composable | bar: {{ bar }}</div>
|
||||
<div>Composable | template: {{ templateAutoImport }}</div>
|
||||
<div>Path: {{ $route.fullPath }}</div>
|
||||
<NuxtLink to="/">
|
||||
Link
|
||||
|
Loading…
Reference in New Issue
Block a user