mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
feat!(nuxt3): extends support for composables/ directory (#3423)
Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
13dd2b98ea
commit
6c083f3d12
@ -1,5 +1,7 @@
|
||||
<script setup>
|
||||
const themeConfig = useRuntimeConfig().theme
|
||||
const foo = useFoo()
|
||||
const bar = getBar()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -8,6 +10,9 @@ const themeConfig = useRuntimeConfig().theme
|
||||
<pre>{{ JSON.stringify(themeConfig, null, 2) }}</pre>
|
||||
<BaseButton>Base Button</BaseButton>
|
||||
<FancyButton>Fancy Button</FancyButton>
|
||||
<br>
|
||||
{{ foo }} {{ bar }}
|
||||
<br>
|
||||
{{ $myPlugin() }}
|
||||
</NuxtExampleLayout>
|
||||
</template>
|
||||
|
3
examples/config-extends/base/composables/foo.ts
Normal file
3
examples/config-extends/base/composables/foo.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { useState } from '#app'
|
||||
|
||||
export const useFoo = () => useState('foo', () => 'foo')
|
@ -1,6 +1,9 @@
|
||||
import { defineNuxtConfig } from 'nuxt3'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
autoImports: {
|
||||
dirs: ['utils']
|
||||
},
|
||||
publicRuntimeConfig: {
|
||||
theme: {
|
||||
primaryColor: 'base_primary',
|
||||
|
1
examples/config-extends/base/utils/bar.ts
Normal file
1
examples/config-extends/base/utils/bar.ts
Normal file
@ -0,0 +1 @@
|
||||
export const getBar = () => 'bar'
|
@ -41,6 +41,9 @@ export default defineNuxtModule({
|
||||
nuxtCtx.set(nuxt)
|
||||
}
|
||||
|
||||
// Mock _extends
|
||||
nuxt.options._extends = nuxt.options._extends || []
|
||||
|
||||
if (opts.nitro) {
|
||||
await setupNitroBridge()
|
||||
}
|
||||
|
@ -36,6 +36,15 @@ export default defineNuxtModule<AutoImportsOptions>({
|
||||
join(nuxt.options.srcDir, 'composables'),
|
||||
...options.dirs
|
||||
]
|
||||
|
||||
// Extend with layers
|
||||
for (const layer of nuxt.options._extends) {
|
||||
composablesDirs.push(resolve(layer.config.srcDir, 'composables'))
|
||||
for (const dir of (layer.config.autoImports?.dirs ?? [])) {
|
||||
composablesDirs.push(resolve(layer.config.srcDir, dir))
|
||||
}
|
||||
}
|
||||
|
||||
await nuxt.callHook('autoImports:dirs', composablesDirs)
|
||||
composablesDirs = composablesDirs.map(dir => normalize(dir))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user