mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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>
|
<script setup>
|
||||||
const themeConfig = useRuntimeConfig().theme
|
const themeConfig = useRuntimeConfig().theme
|
||||||
|
const foo = useFoo()
|
||||||
|
const bar = getBar()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -8,6 +10,9 @@ const themeConfig = useRuntimeConfig().theme
|
|||||||
<pre>{{ JSON.stringify(themeConfig, null, 2) }}</pre>
|
<pre>{{ JSON.stringify(themeConfig, null, 2) }}</pre>
|
||||||
<BaseButton>Base Button</BaseButton>
|
<BaseButton>Base Button</BaseButton>
|
||||||
<FancyButton>Fancy Button</FancyButton>
|
<FancyButton>Fancy Button</FancyButton>
|
||||||
|
<br>
|
||||||
|
{{ foo }} {{ bar }}
|
||||||
|
<br>
|
||||||
{{ $myPlugin() }}
|
{{ $myPlugin() }}
|
||||||
</NuxtExampleLayout>
|
</NuxtExampleLayout>
|
||||||
</template>
|
</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'
|
import { defineNuxtConfig } from 'nuxt3'
|
||||||
|
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
|
autoImports: {
|
||||||
|
dirs: ['utils']
|
||||||
|
},
|
||||||
publicRuntimeConfig: {
|
publicRuntimeConfig: {
|
||||||
theme: {
|
theme: {
|
||||||
primaryColor: 'base_primary',
|
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)
|
nuxtCtx.set(nuxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mock _extends
|
||||||
|
nuxt.options._extends = nuxt.options._extends || []
|
||||||
|
|
||||||
if (opts.nitro) {
|
if (opts.nitro) {
|
||||||
await setupNitroBridge()
|
await setupNitroBridge()
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,15 @@ export default defineNuxtModule<AutoImportsOptions>({
|
|||||||
join(nuxt.options.srcDir, 'composables'),
|
join(nuxt.options.srcDir, 'composables'),
|
||||||
...options.dirs
|
...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)
|
await nuxt.callHook('autoImports:dirs', composablesDirs)
|
||||||
composablesDirs = composablesDirs.map(dir => normalize(dir))
|
composablesDirs = composablesDirs.map(dir => normalize(dir))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user