mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(kit): add helper addAutoImport
(#3030)
This commit is contained in:
parent
09dc06e138
commit
adc44a2d2b
23
packages/kit/src/auto-import.ts
Normal file
23
packages/kit/src/auto-import.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import type { AutoImport } from '../../schema/src/types/imports'
|
||||
import { useNuxt } from './context'
|
||||
import { assertNuxtCompatibility } from './compatibility'
|
||||
|
||||
export function addAutoImport (_autoImports: AutoImport | AutoImport[]) {
|
||||
assertNuxtCompatibility({ bridge: true })
|
||||
|
||||
useNuxt().hook('autoImports:extend', (autoImports: AutoImport[]) => {
|
||||
for (const composable of (Array.isArray(_autoImports) ? _autoImports : [_autoImports])) {
|
||||
autoImports.push(composable)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function addAutoImportDir (_autoImportDirs: String | String[]) {
|
||||
assertNuxtCompatibility({ bridge: true })
|
||||
|
||||
useNuxt().hook('autoImports:dirs', (autoImportDirs: String[]) => {
|
||||
for (const dir of (Array.isArray(_autoImportDirs) ? _autoImportDirs : [_autoImportDirs])) {
|
||||
autoImportDirs.push(dir)
|
||||
}
|
||||
})
|
||||
}
|
@ -8,6 +8,7 @@ export * from './loader/config'
|
||||
export * from './loader/nuxt'
|
||||
|
||||
// Utils
|
||||
export * from './auto-import'
|
||||
export * from './build'
|
||||
export * from './compatibility'
|
||||
export * from './components'
|
||||
|
Loading…
Reference in New Issue
Block a user